OnTriggerStay call

Hey Guys, I am using this code

function OnTriggerStay(other:Collider)
    {
    	if(other.gameObject.tag == "Player" && Input.GetKeyUp(KeyCode.Tab))
    	{
    		onOff = !onOff;	
    		for(i=0;i<target.Length;i++)
    		{
    			if(!doFunction)
    			{
    				if(onOff)
    				{
    					target*.animation.Play(anim);*
  •  			if(wait)*
    
  •  				yield WaitForSeconds(0.4);*
    

_ for (var state : AnimationState in target*.animation)_
_
{_
_
state.speed = 1;_
_
}_
_
}_
_
else*_
* {*
_ for (var state : AnimationState in target*.animation)
{
state.speed = 0;
}
}
}
if(doFunction)
{
target.SendMessage(func);
if(!camAnimPlayed && cam)
{
cam.camera.enabled = true;
cam.animation.Play(camAnim);
camAnimPlayed = true;
}
}
}
}
}*

Which kind of works perfectly, but I sometimes have to jab “TAB” more than once, sometimes five times before it decides to work.
Does anyone else experience this, am I doing something wrong?
Any advice would be great!
Many thanks._

I think the answer might be that you’ve used OnKeyUp in OnTriggerStay instead of Update. The docs say that the button state for OnKeyUp is reset every frame and that it should be called during Update.

Maybe try changing the code to take input during update? Keep track of that and apply during OnTriggerStay, or the other way round…