fgm24/Assets/Scripts/Enemy/EnemyAnimationHandler.cs

52 lines
1.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class EnemyAnimationHandler : MonoBehaviour
{
Animator animator;
bool isDying = false;
public GameObject healthBar;
void Start()
{
animator = GetComponent<Animator>();
if (animator != animator.enabled)
animator.enabled = true;
GetComponentInParent<HealthComponent>().OnHealthZero.AddListener(EnemyDie);
}
void EnemyDie()
{
GetComponentInParent<Collider2D>().enabled = false;
GetComponentInParent<NavMeshAgent>().enabled = false;
if (!isDying)
StartCoroutine(AnimationDie());
isDying = true;
}
IEnumerator AnimationDie()
{
Strangle();
Debug.Log("Strangle");
yield return new WaitForSecondsRealtime(0.1f);
Die();
}
public void Strangle()
{
animator.SetTrigger("Strangle");
}
public void Die()
{
animator.SetTrigger("Die");
AudioManager.PlaySound("Slice_Enemy_SFX", transform.position).volume = 0.65f;
}
public void DestroyGameobject()
{
Destroy(transform.parent.gameObject);
}
}