Can't assign camera to variable.

I have three cameras in my scene. One follows the body of the tank, one follows the turret of the tank (rotation), and eventually, i want one that is a "zoomed-in" view. However, when I go to drag my cameras into the "camera1""camera2" variable slots in the inspector, I just simply cant. No errors or anything, it's just physically impossible to drag it onto the slot.

Here's a screenshot. You can see my code, and variables on the right, and my cameras on the left.

alt text

Here's the code I'm using, and I've seen it a hundred times.

var camera1 : Camera; 
var camera2 : Camera; 

function Start () { 
   camera1.enabled = true; 
   camera2.enabled = false; 
} 

function Update () { 
   if (Input.GetKeyDown ("2")){ 
      camera1.enabled = false; 
      camera2.enabled = true; 
   } 
   if (Input.GetKeyDown ("1")){ 
      camera1.enabled = true; 
      camera2.enabled = false; 
   }     
}

have you put the script on something? I can't attach cameras to the script until I've actually put it on something.

–

If you can, post an answer (not a comment) stating the solution and mark it as accepted. It takes it off the "unanswered" list.

–

Not quite at the bottom, they need to be included in the main namespace and part of the class (see the comments in the snippet above). Here;s the full file I'm using: [RigidbodyFPControllerCardboard.cs][1] [1]: http://baroquedub.co.uk/private/temp/RigidbodyFPControllerCardboard.cs

–

2 Answers

2

When you drag objects like that, it's gonna be Transform (or maybe GameObject?). Anyway, try Transform and then GetComponent(Camera) on them.

Thanks for the help! (Sorry for the late reply...)

–

@TortoRacoon make sure your camera is a prefab as well as the object you’re trying to assign it to