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#.

155984-capture.png

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!

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

public class EquipFlash : MonoBehaviour
{
public GameObject flash;
public bool state = false;

    void Update()
    {
        If (Input.GetKeyUp (KeyCode.E))
            {
             flash.SetActive (!state);
            }        
    }
}

,I would add a variable…
public class EquipFlash : MonoBehaviour
{
public GameObject flash;
public bool state = false;

    void Update()
    {
        If (Input.GetKeyUp (KeyCode.E))
            {
             flash.SetActive (!state);
            }        
    }
}