// *********************************************************************** // Assembly : Game // Author : Kimch // Created : 2020-09-02 // Description : // Last Modified By : // Last Modified On : // *********************************************************************** // // // *********************************************************************** using UnityEngine; namespace G { public class AI_Ride_Enemy2 : MonoBehaviour { #region Field public Transform bullet; private Transform _cha1; private Transform _bullet; private bool _live; private bool _impact; private float _rotLimit; private float _rotSpeed; #endregion #region Method public void Attack() { if (_live) { this.GetComponent().Play("ride_mon_shoot"); var temp = this.GetComponent().PlayQueued("ride_mon_shoot_i"); temp.speed = 0.25f; temp.layer = 1; } } public void Wake() { _live = true; } public void Defeat() { _live = false; } void PlayAnim(string anim) { this.GetComponent().Play(anim); } bool IsPlaying(string anim) { return this.GetComponent().IsPlaying(anim); } #endregion #region Unity private void Awake() { } private void Start() { _cha1 = GameObject.FindWithTag("Player").transform; this.GetComponent()["ride_mon"].speed = 0.25f; this.GetComponent()["ride_mon_shoot"].speed = 0.25f; this.GetComponent()["ride_mon_shoot"].layer = 1; PlayAnim("ride_mon"); InvokeRepeating(nameof(Attack), 4f, Random.Range(3f, 5f)); _bullet = Object.Instantiate(bullet, Vector3.one * 10f, Quaternion.identity); _bullet.gameObject.SetActive(false); } private void Update() { if (!_live) { return; } if (IsPlaying("ride_mon_shoot_i")) { _rotLimit = -1f; _rotSpeed = 8f; if (!_impact) { _bullet.gameObject.SetActive(true); _bullet.position = transform.position + Vector3.up * 0.08f; _bullet.rotation = transform.rotation; _impact = true; } } else if (IsPlaying("ride_mon_shoot")) { _rotLimit = -1f; _rotSpeed = 8f; _impact = false; } else if (IsPlaying("ride_mon")) { _rotLimit = 0f; _rotSpeed = 4f; } var targetDir = _cha1.position - transform.position; targetDir.y = 0f; targetDir = Vector3.Normalize(targetDir); if (targetDir.z > _rotLimit) { transform.forward = Vector3.Lerp(transform.forward, targetDir, Time.deltaTime * _rotSpeed); } else { transform.forward = Vector3.Lerp(transform.forward, Vector3.forward, Time.deltaTime * 6f); } } #endregion } }