Im making a 2D platformer and Ive set up a 3 heart health system that takes away hearts, similar to Klonoa games. Now while ive made sure that certain obstacles can one shot the player(pitfalls), when they take normal damage, it does nothing until I go past the current health(3)into the negative(-1) which then freezes the game. My health code is this: `using UnityEngine;
using System.Collections;
public class HealthManager : MonoBehaviour {
private LevelManager levelManager;
//Health Points data
public int curHealth;
public int maxHealth = 3;
// Use this for initialization
void Start () {
curHealth = maxHealth;
}
// Update is called once per frame
void Update () {
if (curHealth > maxHealth) {
curHealth = maxHealth;
if (curHealth <= 0) {
Death() ;
}
}
}
public void Death () {
//Restart from dying
Application.LoadLevel(Application.loadedLevel);
}
public void Damage(int dmg) {
curHealth -= dmg;
}
}
`
And my Damage code is this:
`using UnityEngine;
using System.Collections;
public class HurtPlayer : MonoBehaviour {
private HealthManager healthManager;
void Start () {
healthManager = FindObjectOfType<HealthManager> ();
}
void OnTriggerEnter2D(Collider2D other) {
if (other.tag == "Player") {
healthManager.Damage(1);
}
}
}`
I at first had the health mixed in the player script, but I separated them to have an easier time when I try to add a “lives” system. I really would love some help here as I’ve been fighting with it for days.