- Home /
Switching cameras with the mouse button
Okay, here is my problem. I have a simple 2d (actually it's 3D with an overhead camera, but anyway) I have about 22 cameras going in sequential order and when I click a certain button on the GUi, it switches to the next one. But nothing works and there is no switching of cameras. It should work that when you start at the Main Camera (camera 1)and then when you click the button (which is GUI) you go to the next one (cam 2), but nothing works. Can anyone at least point me in the right direction of what to do?
We could probably help you if you provided a bit more information about what's going on. Can you add the relevant couple lines of code for the GUI button and camera object activation / deactivation?
Answer by Grady · Oct 01, 2011 at 09:08 AM
The standard procedure for switching between cameras when pressing the left mouse button would be something like this:
var camera1 : Camera; var camera2 : Camera;
function Start(){ camera1.enabled = true; camera2.enabled = false; }
function Update(){
if(Input.GetButonDown("Fire1")){
if(camera1.enabled == true){
camera1.enabled = false;
camera2.enabled = true;
}
else{
camera1.enabled = true;
camera2.enabled = false;
}
}
}
Drag the main camera, (the one that will start active) into the camera1
variable. Then drag the other one into the camera2
variable. I haven't tested this, but it should work, if it doesn't, just comment back and I will fix it, I took a bit of a shortcut that I normally don't, but it should work as is!!!!!
-Grady
Hi Grady, i am trying this out now, but when i try to assign which camera is which in the inspector, the assets folder shows no cameras to select, both cameras are in my assets list... ?
Your answer
Follow this Question
Related Questions
Switching cameras with the click of the mouse 1 Answer
Multiple Camera.main.ScreenPointToRay 1 Answer
Add multiple cameras problems 1 Answer