gameObject.enabled not working

So i am making a script that allows me to cycle through two cameras when i press tab. There is a first person and third person camera. Which are defined in variables in the script. Ex. my variable is thirdPersonCamera and the line of code is

thirdPersonCamera.enabled = true;

Is there something wrong with this? Because the error message is

MissingFieldException: Field ‘UnityEngine.GameObject.enabled’ not found.

Any help is appreciated thank you.

For any future readers as of Unity 5 = true; is depricated. This is now called SetActive(true)



The error explains it all. There is no ‘enabled’ variable that is associated with a Game Object. What you’re most likely thinking of is ‘active’ when you are accessing a Game Object directly. So what you’re most likely looking for is " = true; ". Camera’s do have an ‘enabled’ variable, and the reason why you’re most likely not getting access to it ( i’m guessing ) is that you’re declaring the camera as a GameObject when it needs to be declared as a Camera in your variable declarations. Otherwise, enabled would work.