I am trying to make it so that if the player gets to close to an enemy they lose 20 health. But it only gets to the first debug.Log.
I have probably made a very stupid mistake.
Here are my two scripts.
public class Enemy : MonoBehaviour {
public GameObject Player;
private Playerhealth access;
public int player;
void Start() {
access = Player.GetComponent<Playerhealth>();
player = access.playerHealth;
}
void OnCollisionEnter(Collision collision) {
if (collision.gameObject.tag == "Player") {
player -= 20;
Debug.Log("hit");
}
}
}
public class Playerhealth : MonoBehaviour {
public int playerHealth = 100;
void Dead() {
if (playerHealth == 0) {
Destroy(this.gameObject);
Debug.Log("you Died");
}
}
}