45 lines
1.0 KiB
C#
45 lines
1.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.AI;
|
|
|
|
public class EnemyAnimationHandler : MonoBehaviour
|
|
{
|
|
Animator animator;
|
|
void Start()
|
|
{
|
|
animator = GetComponentInChildren<Animator>();
|
|
if (animator != animator.enabled)
|
|
animator.enabled = true;
|
|
|
|
GetComponent<HealthComponent>().OnHealthZero.AddListener(EnemyDie);
|
|
}
|
|
void EnemyDie()
|
|
{
|
|
GetComponent<Collider2D>().enabled = false;
|
|
GetComponent<NavMeshAgent>().enabled = false;
|
|
|
|
StartCoroutine(AnimationDie());
|
|
}
|
|
|
|
IEnumerator AnimationDie()
|
|
{
|
|
Strangle();
|
|
yield return new WaitForSecondsRealtime(1f);
|
|
Die();
|
|
while (animator.GetCurrentAnimatorStateInfo(0).normalizedTime < 1f)
|
|
yield return new WaitForEndOfFrame();
|
|
Destroy(gameObject);
|
|
}
|
|
|
|
public void Strangle()
|
|
{
|
|
animator.SetTrigger("Die");
|
|
}
|
|
public void Die()
|
|
{
|
|
animator.SetTrigger("Die");
|
|
|
|
}
|
|
}
|