So I have this code
void OnCollisionEnter (Collision col){
if (col.gameObject.name == "Enemy") {
combatStart = true;
}
}
// Update is called once per frame
void Update () {
//combat phase
if (Input.GetMouseButtonDown (0) && combatStart == true) {
enemyHealth -= (Random.Range (50, 125));
if (enemyHealth <= 0) {
enemyHealth = 0;
}
Debug.Log (enemyHealth);
Debug.Log (playerHealth);
}
}
In my mind, this makes sense, when the player collides with the “Enemy”, and they are clicking MB 0 (LMB) they will begin to chunk the enemy health away. However, it’s not detecting that I’ve collided with the enemy. Can someone explain to me why this is happening, and possibly propose a fix?