How do you activate a camera

Hi all, I’m want a enable/disable camera toggle when I press a key. I can get the camera to disable but I cant enable it. The camera is not a child of any object & it has no children

public Camera  RADCAM;

In update

if (Input.GetKeyDown ("g")) {

            RADCAM.enabled = false ;         

                }

if I change the false to true & turn the camera off in the inspector then run it the camera wont turn on when I press the g key. I’ve tried numerous examples I’ve found but none of them work either. I have dragged the camera to the RADCAM slot in the inspector.
Also & not sure if this has somthing to do with it but the script is attached to the main camera.

Thanks in advance

& why is it so difficult to do somthing that should be really simple … please help

try this

if (Input.GetKeyDown ("g")) {
            RADCAM.enabled =  !RADCAM.enabled;       
                }

Yeah that works if I have the camera enabled at the start of the game, thanks so much.
If the camera is not enabled at the runtime then it does nothing but thats a great help thanks.

your welcome, the “!” is the “opposite value”, if true become false, if false become true

I made a slight adjustment and got it working whether it’s active at runtime or not …

if (Input.GetKeyDown ("g")) {

            if (!RADCAM.isActiveAndEnabled)  RADCAM.enabled = true;
            else RADCAM.enabled = false;
1 Like