using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class zombHit : MonoBehaviour
{
public GameObject player;
public float damage;
private void OnTriggerStay(Collider other)
{
Debug.Log("Hitzone ENTERED!");
if (other.gameObject == player)
{
GetComponentInParent<NavMeshAgent>().speed = 0;
GetComponentInParent<Animator>().Play("Attack");
GameObject.FindGameObjectWithTag("Player").GetComponent<Target>().TakeDamage(damage);
}
}
private void OnTriggerExit(Collider other)
{
if (other.gameObject == player)
{
GetComponentInParent<NavMeshAgent>().speed = GetComponentInParent<EnemyAI>().chasemoveSpeed;
}
}
}
So, what this script does is when player is in contact of collider, the enemy plays a clip from the animator and takes away the players health. However, because the ontriggerstay is an update function it takes away the players health every frame. Iām trying to figure out how to make it so that it only takes away when the animation plays. I tried with ontriggerenter, but the enemy would only attack once if player enters it.