Im working on a player health system for my fps. i have the basics working im just trying to make it where when the enemy touchs the player prefab the player dies which iv kinda done but not only do you die when you touch the enemy but you die everytime you touch a collider`
public class PlayerHealth : MonoBehaviour {
public float startingHealth = 100.0f;
public float maxHealth = 100.0f;
public float currentHealth;
public Transform enemy;
private bool dead = false;
// Use this for initialization
void Start () {
currentHealth = startingHealth;
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown("space"))
{
die();
}
}
void ChangeHealth(float amount){
if(currentHealth <= 0 && !dead)
die();
else if(currentHealth > maxHealth)
currentHealth = maxHealth;
}
void OnCollisionEnter(Collision collision){
die();
Debug.Log("Killed by Enemy");
}
void die(){
dead = true;
Destroy(gameObject);
Debug.Log("Player dead");
}
}
`