- Home /
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.
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.
Answer by DaveA · Apr 09, 2011 at 04:46 AM
When you drag objects like that, it's gonna be Transform (or maybe GameObject?). Anyway, try Transform and then GetComponent(Camera) on them.
Thanks, but it was a simple, dumb mistake. I hadn't attached the script!
It would be very helpfull if you explained that "Attaching the script", I'm having the exact same problem, except that I have other objects successfully assigned to the script, is only the fkn camera that is not assigning for some reason
Answer by In0sc0p3dJFK · May 13, 2021 at 02:40 AM
@TortoRacoon make sure your camera is a prefab as well as the object you're trying to assign it to
Your answer
Follow this Question
Related Questions
Main Camera Switch? 3 Answers
changing player (getting in vehicles) 3 Answers
camera switch not working 3 Answers
Single Camera Lerping between three characters? (code provided) 0 Answers
Changing variable numbers depending on current player model. 1 Answer