x


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.

more ▼

asked Oct 13 '10 at 06:38 PM

Oninji gravatar image

Oninji
332 43 47 50

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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();
}
more ▼

answered Oct 13 '10 at 06:46 PM

skovacs1 gravatar image

skovacs1
10k 11 25 91

Well, seems there's no escaing doing it this way then. Thanks.

Oct 13 '10 at 06:55 PM Oninji
(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Feb 25 '12 at 03:14 AM

Fubiou gravatar image

Fubiou
30 12 12 15

(comments are locked)
10|3000 characters needed characters left

If OnTriggerStay doesnt test for exit, there is no reason for exist, it is the same as OnTriggerEnter.

more ▼

answered Feb 24 '12 at 05:24 AM

Fubiou gravatar image

Fubiou
30 12 12 15

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 instead of an answer...

Feb 24 '12 at 05:30 AM Bunny83
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5094
x3465
x479
x174

asked: Oct 13 '10 at 06:38 PM

Seen: 1571 times

Last Updated: Feb 25 '12 at 03:14 AM