// *********************************************************************** // Assembly : Game // Author : Kimch // Created : 2020-09-02 // Description : // Last Modified By : // Last Modified On : // *********************************************************************** // // // *********************************************************************** using UnityEngine; namespace G { /// /// /// public class Bullet_magicmissile : MonoBehaviour { public float closetime = 3f; public float homingrate; public float homingspeed; private float _delay; private Quaternion _rotate; private Vector3 _originscale; private Vector3 _reduceVector; private void Awake() { _originscale = transform.localScale; } private void Start() { _reduceVector = new Vector3(0.5f, 1f, 1f); InvokeRepeating(nameof(SetDir), 0f, 0.1f); } private void OnEnable() { _delay = 0f; transform.localScale = _originscale; } public void SetDir() { var directionVector = EntityMainPlayer.Instance.position - transform.position; directionVector.y = 0f; if (directionVector != Vector3.zero) { _rotate = Quaternion.LookRotation(directionVector); } } private void Update() { transform.rotation = Quaternion.Lerp(transform.rotation, _rotate, Time.deltaTime * homingrate); transform.position += transform.forward * (Time.deltaTime * homingspeed); _delay += Time.deltaTime; if (_delay > closetime) { Vector3 localScale = transform.localScale; localScale -= _reduceVector * (Time.deltaTime * 1.5f); transform.localScale = localScale; if (localScale.z < 0.02f) { transform.position = Vector3.one * 4f; this.gameObject.SetActive(false); } } } } }