// *********************************************************************** // Assembly : Game // Author : Kimch // Created : 2020-09-08 // Description : // Last Modified By : // Last Modified On : // *********************************************************************** // // // *********************************************************************** using UnityEngine; namespace G { /// /// 武器掉落 /// public class WeaponDrop : MonoBehaviour { private float _maxY = 1.8f; private bool _drop; private Vector3 _rotateAxis; private void Awake() { _rotateAxis = transform.right; } public void DropCancel() { _drop = false; CancelInvoke(nameof(Disappear)); } public void Drop(bool destroy) { CancelInvoke(nameof(Disappear)); if (destroy) { Object.Destroy(this.gameObject, 3.5f); } else { Invoke(nameof(Disappear), 3.5f); } _drop = true; _maxY = 1.7f; } private void Disappear() { this.transform.position = Vector3.one * 4f; this.gameObject.SetActive(false); } private void Update() { if (_drop) { Vector3 position = this.transform.position; if (position.y > 0.1f) { this.transform.Rotate(_rotateAxis * (position.y * 72f)); _maxY -= 3.5f * Time.deltaTime; this.transform.position = position + Vector3.up * (_maxY * Time.deltaTime); return; } position.y = 0.1f; this.transform.position = position; _drop = false; } } } }