123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
-
- using UnityEngine;
- public class EnemyBehavior : MonoBehaviour {
- private const float lifeMax = 100;
- public float life = lifeMax;
- private SphereCollider capsuleCollider;
- private bool isDying = false;
- private void Start()
- {
- life = lifeMax;
- capsuleCollider = GetComponent<SphereCollider>();
- capsuleCollider.enabled = true;
- isDying = false;
- }
-
- void Update () {
- }
-
-
-
-
- public void Dammage(float value)
- {
- if (!isDying)
- {
- life -= value;
- if (life < 0)
- {
- Dead();
- }
- }
- }
-
-
-
- public void StartSinking()
- {
- capsuleCollider.enabled = false;
- Destroy(gameObject, 2.0f);
- }
-
-
-
- private void Dead()
- {
- isDying = true;
- GetComponent<UnityEngine.AI.NavMeshAgent>().enabled = false;
- GetComponent<Animator>().SetTrigger("Dead");
-
- }
- private void OnDestroy()
- {
- isDying = false;
- }
- }
|