I tried using this in my code and had issues. I would like to understand how to use and apply OnTriggerStay in my script. In the code I’m trying to decrease uses health while on the fire but none of the code runs when conditions are met in game.
function OnTriggerStay (other : Collider)
{
if (hit.gameObject.tag == "fire")
{
Debug.Log("hit fire tag");
var healthScript: gui = Camera.main.GetComponent("gui");
if(healthScript.health > 0)
{
if (healthScript != null){
healthScript.health = healthScript.health -1;
Debug.Log("dying!");
}
else if (hit.gameObject.tag == "heal")
{
var healthScript2: gui = Camera.main.GetComponent("gui");
if(healthScript2.health < 100)
{
if (healthScript2 != null){
healthScript2.health = healthScript.health +1;
Debug.Log("healing!");}
}
}
}
}
}