2024-02-03 10:52:24 +01:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
2024-02-04 02:26:11 +01:00
|
|
|
using UnityEngine.AI;
|
2024-02-03 10:52:24 +01:00
|
|
|
|
|
|
|
public class EnemyAnimationHandler : MonoBehaviour
|
|
|
|
{
|
|
|
|
Animator animator;
|
2024-02-04 02:34:23 +01:00
|
|
|
bool isDying = false;
|
2024-02-03 10:52:24 +01:00
|
|
|
void Start()
|
|
|
|
{
|
2024-02-04 02:34:23 +01:00
|
|
|
animator = GetComponent<Animator>();
|
2024-02-03 21:31:14 +01:00
|
|
|
if (animator != animator.enabled)
|
|
|
|
animator.enabled = true;
|
2024-02-03 10:52:24 +01:00
|
|
|
|
2024-02-04 02:34:23 +01:00
|
|
|
GetComponentInParent<HealthComponent>().OnHealthZero.AddListener(EnemyDie);
|
2024-02-03 10:52:24 +01:00
|
|
|
}
|
2024-02-04 00:08:25 +01:00
|
|
|
void EnemyDie()
|
|
|
|
{
|
2024-02-04 02:26:11 +01:00
|
|
|
GetComponent<Collider2D>().enabled = false;
|
|
|
|
GetComponent<NavMeshAgent>().enabled = false;
|
|
|
|
|
2024-02-04 00:08:25 +01:00
|
|
|
StartCoroutine(AnimationDie());
|
|
|
|
}
|
|
|
|
|
|
|
|
IEnumerator AnimationDie()
|
|
|
|
{
|
2024-02-04 02:34:23 +01:00
|
|
|
isDying = true;
|
2024-02-04 00:08:25 +01:00
|
|
|
Strangle();
|
2024-02-04 02:34:23 +01:00
|
|
|
Debug.Log("Strangle");
|
|
|
|
yield return new WaitForSecondsRealtime(0.1f);
|
2024-02-04 00:08:25 +01:00
|
|
|
Die();
|
|
|
|
}
|
|
|
|
|
2024-02-03 10:52:24 +01:00
|
|
|
public void Strangle()
|
|
|
|
{
|
2024-02-04 02:34:23 +01:00
|
|
|
animator.SetTrigger("Strangle");
|
2024-02-03 10:52:24 +01:00
|
|
|
}
|
|
|
|
public void Die()
|
|
|
|
{
|
|
|
|
animator.SetTrigger("Die");
|
2024-02-04 02:34:23 +01:00
|
|
|
}
|
|
|
|
public void DestroyGameobject()
|
|
|
|
{
|
|
|
|
Destroy(transform.parent.gameObject);
|
2024-02-04 00:08:25 +01:00
|
|
|
|
2024-02-03 10:52:24 +01:00
|
|
|
}
|
|
|
|
}
|