- Home /
Question by
sandersekreve · May 07, 2020 at 04:17 PM ·
2dcameras
unity 2d switch between cameras
hey, im making a 2d game, but i have a one problem. i want the camera to switch to another camera if the player runs off the first one.
my MainCamera has the tag MainCamera and the second camera is called Camera2 with the tag Camera2.
I have tried this to test if the camera switches but it says that ";" is expected at the var cam1 : MainCamera;
var cam1 : MainCamera;
var cam2 : Camera2;
function Start() {
cam1.enabled = true;
cam2.enabled = false;
}
function Update() {
if (Input.GetKeyDown(KeyCode.C)) {
cam1.enabled = !cam1.enabled;
cam2.enabled = !cam2.enabled;
}
}
Any help is much appriciated!
Comment
Answer by FZ_Applications · May 08, 2020 at 08:25 PM
I'm not a JS programmer, but I think you have to write:
//Assign these variables in the inspector:
var cam1 : Camera;
var cam2 : Camera;
Your answer
Follow this Question
Related Questions
Render entire sprite in 3D but with depth according to position. 2 Answers
Make sprite ignore image effect 0 Answers
2D Animation does not start 1 Answer
basic 2d sidescroller camera 2 Answers