- Home /
Inverse function of OnTriggerStay?
Hellow,
Like the title say, is there a function that is inverse to OnTriggerStay? I need to detect when the object is inside and when it's outside.
Or can I divide the function to tell it that when it's on True do "X thing" and when False do "Y thing"
Thanks.
A bit late, but there´s no need to do any check in any other function:
OntriggerStay (Collider other)
{
if(other.transform.compareTag("enemy"))
{
//theres a trigger
}
if(!other.transform.compareTag("enemy"))
{
//no one is triggering
}
}
Answer by skovacs1 · Oct 13, 2010 at 06:46 PM
No, there is no OnTriggerOutside or some such.
OnTriggerStay is called once per frame just as Update is. Using OnTriggerEnter and OnTriggerExit, you can achieve what you describe via a boolean flag:
var inside : boolean = false;
function OnTriggerEnter() { inside = true; }
function OnTriggerExit() { inside = false; }
function Update() { if(inside) DoX(); else DoY(); }
Well, seems there's no escaing doing it this way then. Thanks.
You are already using a trigger, why using an update also?
Answer by Fubiou · Feb 24, 2012 at 05:24 AM
If OnTriggerStay doesnt test for exit, there is no reason for exist, it is the same as OnTriggerEnter.
First of all, this is not an answer to the question, so why do you post this as answer?. Second OnTriggerStay is not the same as OnTriggerEnter. OnTriggerEnter is called once when you enter the trigger. OnTriggerStay is called every frame while you're inside of the trigger. When you leave the trigger it isn't called anymore.
Finally, when you want to ask a question, how about post a question ins$$anonymous$$d of an answer...
Answer by Fubiou · Feb 25, 2012 at 03:14 AM
it is not enough, not always, for exemple, in some circunstancy you miss the moment of "OnTriggerExit" for some complex reason such as parenting, the "stay" will be still confirmed. Actually if there is not the reverse effect, there is no reason for "OnTriggerStay", it would be the same thing of OnTriggerEnter
Your answer
Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
variable = true from another script 2 Answers
Enemy sound detection 5 Answers
First person shooter shoot Function 3 Answers