- Home /
How to use one trigger that will set object active then when hit the 2nd time will deactivate it?
Hello. I have a Scene as follows. (And the TV is ON at start) a TV with a TVON Texture on it already, a TV Remote, A Black quad for TVOFF. An animation on the remote, And a Trigger.
When i hit the trigger, the trigger becomes inactive, the remote animation plays, then after 1 sec. the TVOFF quad becomes active and covers the TV making it look off.
Ok so now the TV went from on to off and played a remote animation. And I can't re hit the trigger. AWESOME! that works.
Now here is where i'm stumped.
So the TV is off. I would like to turn the TV back on again and also play that same remote animation. so now i need to reactivate the trigger to..... 1. How can I do this same thing again with the same trigger BUT make my TVOFF game object become deactive instead of active?? So when i hit the trigger again next time it will turn the TV Back on?? 2. Would an if statement work in here? Seems like it could be pretty easy. Please help.
( I cannot provide a script because i'm using Blox 2 visual scripting.)
However, its very script like so as long as i know what i would need in a script i could incorporate that into blox 2.
Answer by wibble82 · Sep 06, 2015 at 02:02 PM
The details of your question are a little confusing, so I'll just say how I'd do it.
In my 'OnTriggerEnter' function, I'd have a simple statement like this:
//check if currently active, and turn it on or off accordingly
if(mytargetobject.activeSelf)
{
mytargetobject.SetActive(false);
}
else
{
mytargetobject.SetActive(true);
}
i.e. you are asking the 'tv' if it is active. If it is, you deactivate it. If not, you activate it. I'd imagine you can extent this concept into your script somehow?
It's even shorter like this:
target.SetActive(!target.activeInHierarchy);
O$$anonymous$$G!!! Thank you! I took what you said not thinking I could actually get this to work with Blox 2. And I can't believe it actually is working! I don't even know how this works but it does thanks to you. Now I see blox 2 is even more like actual scripting than i though! You saved me alot of time.