// *********************************************************************** // Assembly : Game // Author : Kimch // Created : 2020-09-02 // Description : // Last Modified By : // Last Modified On : // *********************************************************************** // // // *********************************************************************** using UnityEngine; namespace G { /// /// 怪物攻击 /// public class EnemyDamage : MonoBehaviour { public int damage; public bool impactDestroy; public float destroytime; public float colliderofftime; private float _currentTime; private Collider _collider; private int _hit = 0; private void Awake() { _collider = this.GetComponent(); _currentTime = 0f; } private void OnEnable() { _currentTime = 0f; } private void OnTriggerEnter(Collider other) { if (other.gameObject.layer == GameLayer.AllyLayer) { Vector3 forward = transform.forward; forward.y = damage; if (EntityCart.Instance) EntityCart.Instance.Damaged(forward); else EntityMainPlayer.Instance.Damaged(forward, _hit); if (impactDestroy) { this.gameObject.SetActive(false); transform.position = Vector3.one * 5f; } } } public void PressDamage(int a) { damage = a; } public void SetDamage(int d, int hit) { damage = d; _hit = hit; } private void Update() { if (destroytime > 0f) { _currentTime += Time.deltaTime; if (colliderofftime > 0f && _currentTime >= colliderofftime) { _collider.enabled = false; } if (_currentTime >= destroytime) { _currentTime = 0f; this.gameObject.SetActive(false); transform.position = Vector3.one * 5f; _collider.enabled = true; } } } } }