public int health = 25000;
private int healthadd;
public GameObject player;
public Text healths;
public bool infire = true;
public int damage = 1;
void Start()
{
}
void Awake ()
{
}
void OnTriggerEnter (Collider start)
{
if (start.gameObject.name == "start")
{
infire = false;
}
}
void OnTriggerStay (Collider start)
{
if (start.gameObject.name == "start")
{
infire = false;
}
}
void OnTriggerExit (Collider start)
{
if (start.gameObject.name == "start")
infire = true;
}
void Update()
{
if (health >= 35001) {
healthadd = 2;
}
if (health <= 35000) {
healthadd = 5;
}
}
void FixedUpdate()
{
if (health > 999801)
{
health = 999801;
}
if (infire == false)
{
health += healthadd;
}
else
{
health -= 0;
}
if(Input.GetKey(KeyCode.LeftShift))
{
DamagePlayer(5);
}
DamagePlayer (1);
uihealths () ;
if (health <= 0)
{
health = 0;
}
}
public void DamagePlayer (int damage)
{
health -= damage;
}
void uihealths ()
{
healths.text = "Warmth: " + (health / 50).ToString ();
}
}
My game object “start” has an auto destroy script to destroy itself after 180 seconds, and a collider. The player has a collider, and when a trigger is detected the player gains 50 points of health per second. The problem is when the object destroys itself when the player is inside its collider, my script doesn’t detect that the player has exited the object.