I am not an expert in unity but I 've been trying to make an enemy health script which isn’t working properly. The number of ‘hits’ isn’t increasing at all even on collisions. the collisions happen and enemy is pushed away by bullets but the bullet hits do not increase. Please help.
public class EnemyScript_1 : MonoBehaviour
{
public int hits = 0;
public NavMeshAgent nav;
public Animator anims;
void Start()
{
nav.GetComponent<NavMeshAgent>();
anims = GetComponent<Animator>();
hits = 0;
}
void Update()
{
GameObject player = GameObject.FindGameObjectWithTag("Player");
Vector3 playerpos = player.transform.position;
nav.SetDestination(playerpos);
Debug.Log(hits.ToString());
if (hits >= 4)
{
Destroy(this.gameObject);
}
}
void OnCollisionEnter(Collision other)
{
if (other.gameObject.tag == "Finish")
{
hits += 1;
}
}
}