Varaible not decementing OnTriggerExit

Hi,

I added a rigid body to my player that I can control and move around the arena. I have the following C# Script which detects if my player has 'stayed' or 'exited' the Plane game object:

public float x = 0;

//...

void OnTriggerStay(Collider other)
{
   if ( x <= 50 ) x++;
}

void OnTriggerExit(Collider other) 
{
  // does happen when below is commented but not vise versa
  Debug.Log("outside of Plane");  

  //if ( x < 50 && > 0 ) x--;
}

Just wondering why.

What I don't want to do is this:

//...
bool isHere = false; 
void UpDate()
{
 if (isHere == false) x--;
}
void OnTriggerStay(Collider other)
{
   isHere = true;
}
void OnTriggerExit(Collider other) 
{
   Debug.Log("leaving plane..");
   isHere = false;
}

Which works, but can this be done only in the subrountine OnTriggerExit? I am all ears.

It seems like you think "OnTriggerExit" is called repeatedly if the object is not in the trigger. That is not the case, as it is only called once on the same frame the object leaves the trigger.

Therefore you will have to use a boolean to control the logic flow similar to what you have in the second set of code. Also if this is for points or something similar you should use something like Time.time or Time.deltaTime to do this over time, otherwise it will happen every frame causing the incrementing/decrementing to be frame dependent rather than time dependent, and very fast in most cases(shooting to 50 or zero in less than a second).