185 lines
5.5 KiB
C#
185 lines
5.5 KiB
C#
// ***********************************************************************
|
|
// Assembly : Game
|
|
// Author : Kimch
|
|
// Created : 2020-09-02
|
|
// Description :
|
|
// Last Modified By :
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "Pet_horse" company="Kimch"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
using UnityEngine;
|
|
|
|
namespace G
|
|
{
|
|
public class Pet_horse : MonoBehaviour
|
|
{
|
|
public AudioClip horse_cry;
|
|
|
|
private Transform cha1;
|
|
|
|
private bool _rideOn;
|
|
|
|
private bool _skillOn;
|
|
|
|
private bool _disappear;
|
|
|
|
private float _disappearDelay;
|
|
|
|
private EntityMainPlayer _scriptCha1;
|
|
private Animation _animation;
|
|
|
|
#region Method
|
|
|
|
public void Rideing(bool _stop)
|
|
{
|
|
if (_stop)
|
|
{
|
|
_rideOn = false;
|
|
transform.parent = null;
|
|
transform.position = Vector3.one * 71f;
|
|
}
|
|
else
|
|
{
|
|
_rideOn = true;
|
|
transform.parent = cha1;
|
|
transform.position = transform.root.position;
|
|
transform.rotation = transform.root.rotation;
|
|
}
|
|
}
|
|
|
|
public void GetOffHorse()
|
|
{
|
|
_rideOn = false;
|
|
transform.parent = null;
|
|
_animation.Stop();
|
|
_animation.Play("horse_cry");
|
|
var temp = _animation.PlayQueued("horse_run", QueueMode.CompleteOthers);
|
|
temp.speed = _animation["horse_run"].speed;
|
|
_disappear = true;
|
|
this.GetComponent<AudioSource>().Stop();
|
|
}
|
|
|
|
public void RideandCry()
|
|
{
|
|
transform.parent = cha1;
|
|
transform.position = transform.root.position;
|
|
transform.rotation = transform.root.rotation;
|
|
_animation.Stop();
|
|
this.GetComponent<AudioSource>().PlayOneShot(horse_cry);
|
|
_animation.Play("horse_cry");
|
|
var temp = _animation.PlayQueued("horse_stand");
|
|
temp.speed = _animation["horse_stand"].speed;
|
|
}
|
|
|
|
public void RunStart(bool a)
|
|
{
|
|
if (a)
|
|
{
|
|
_animation.Play("horse_run");
|
|
this.GetComponent<AudioSource>().Play();
|
|
}
|
|
else
|
|
{
|
|
_animation.CrossFade("horse_stand");
|
|
this.GetComponent<AudioSource>().Stop();
|
|
}
|
|
}
|
|
|
|
public void SkillOn()
|
|
{
|
|
this.gameObject.SetActive(true);
|
|
float f = Random.Range(0, 360);
|
|
Vector3 position = cha1.position + new Vector3(Mathf.Cos(f), 0f, Mathf.Sin(f)) * 2f;
|
|
transform.position = position;
|
|
_skillOn = true;
|
|
_disappear = false;
|
|
|
|
Vector3 vector = cha1.position - transform.position;
|
|
vector.y = 0f;
|
|
if (vector != Vector3.zero)
|
|
{
|
|
transform.rotation = Quaternion.LookRotation(vector);
|
|
}
|
|
_animation.Play("horse_run");
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Unity
|
|
|
|
private void Awake()
|
|
{
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
_animation = GetComponent<Animation>();
|
|
_animation["horse_run"].layer = 1;
|
|
_animation["horse_stand"].layer = 1;
|
|
_animation["horse_cry"].layer = 1;
|
|
_animation["horse_jump"].layer = 1;
|
|
_animation["horse_run"].speed = 0.6f;
|
|
_animation["horse_stand"].speed = 0.1f;
|
|
_animation["horse_cry"].speed = 0.32f;
|
|
_animation["horse_jump"].speed = 0.3f;
|
|
|
|
cha1 = GameObject.FindWithTag("Player").transform;
|
|
_scriptCha1 = cha1.GetComponent<EntityMainPlayer>();
|
|
|
|
_animation.Play("horse_stand");
|
|
}
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (other.transform.IsChildOf(cha1) && !_rideOn)
|
|
{
|
|
_scriptCha1.RideHorse();
|
|
_rideOn = true;
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (_disappear && !_animation.IsPlaying("horse_cry"))
|
|
{
|
|
if (_disappearDelay < 3f)
|
|
{
|
|
_disappearDelay += Time.deltaTime;
|
|
transform.position += transform.forward * Time.deltaTime * 0.8f;
|
|
return;
|
|
}
|
|
_disappear = false;
|
|
_disappearDelay = 0f;
|
|
transform.position = Vector3.one * 4f;
|
|
this.gameObject.SetActive(false);
|
|
}
|
|
else if (_skillOn)
|
|
{
|
|
var horseDistance = Vector3.Distance(cha1.position, transform.position);
|
|
if (horseDistance <= 1.5f && !_rideOn)
|
|
{
|
|
_animation.Stop();
|
|
_animation.Play("horse_jump");
|
|
var temp = _animation.PlayQueued("horse_stand");
|
|
temp.speed = _animation["horse_stand"].speed;
|
|
_rideOn = true;
|
|
}
|
|
|
|
if (!_animation.IsPlaying("horse_stand"))
|
|
{
|
|
transform.position = Vector3.Lerp(transform.position, cha1.position, Time.deltaTime * 3.5f);
|
|
}
|
|
else
|
|
{
|
|
_skillOn = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|