- Home /
How do i toggle active a game object??
I Can Toggle off my flashlight, but i can't toggle it back on, sorry if this sounds stupid, i'm new to c#.
Answer by Vipertex13 · Apr 06, 2020 at 09:51 PM
You didn't turn the flashlight on so I think you should add if(input.GetKeyUp(KeyCode.E)) { flash.SetActive(!false); } else if (input.GetKey(KeyCode.E)) { flash.SetActive(!True); }
Try this is this C# or JavaScript
Answer by TCMOREIRA · Apr 06, 2020 at 09:59 PM
You're almost there!
All you need to do is grab hold of the variable which contains the boolean value representing whether or not the flashlight is Active. For that purpose simply access 'flash.IsActive()'.
This has to occur like this 'flash.SetActive(!flash.IsActive());'.
It would also look nicer if you'd put 'flash.IsActive()' inside a local variable (inside the if statement).
The problem with putting '!false' is that it will always return a constant 'true' value (the negation (inverse) of false).
More of a Game Design sillyness here but shouldn't Flashlight be set to 'F'?
Cheers!
Your answer
Follow this Question
Related Questions
How to implement tokenization of game characters? 1 Answer
Can't display my Countdown timer text on my end menu. (newbie needing help) 1 Answer
a way to predict players position to be able to be hit by projectiles 0 Answers
bool doesn't change?? 0 Answers
Found Spheres Colliders and add it to cloth spheres colliders 1 Answer