OnTriggerStay

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!");}
				}
			}
		}
	}
}

Have you tried a simple sanity check?

function OnTriggerStay (other : Collider)
{
    Debug.Log("OnTriggerStay");
}

It may be the initial if statement. The variable passed into the function, “other”, is the Collider that your script’s Collider is currently colliding with. If that other Collider is meant to be the fire, then try this if statement instead:

if(other.tag == "fire")

Tried that, I get an error message saying Unexpected token …
I know it’s the initial statement that doesn’t run since the rest of the code runs fine with the function OnControllerColliderHit (hit : ControllerColliderHit){
I ran the check to make sure too.

the other tag is meant to be for fire or heal. The code is suppose to work when character Controller is on a collider of that tag.