- Home /
First Person Camera disabling
I am using the built in 1st person controller and am trying to script for a camera change from the player camera to a world map camera, using this script:
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; }
}
This is not working however. I am getting the world map view, but it does not change back to the player camera when I click the button again. I think it is because the first person camera is not disabling, but I am not sure. Please help.
Are both cameras tagged $$anonymous$$ainCamera? Note you're saying "when I click the button again" - you have different keys for different cameras.
I just tested your script and it works fine. Be sure you have both cameras linked to your script and if you're testing within the editor make sure you are inside the game tab when pressing "1" or "2". You can check to what the variables are linked to by clicking on them in the inspector. The linked target will be highlighted
yes im sorry, that was not the correct script, that was the original, but I altered it to be when I click a Gui Texture ins$$anonymous$$d
Answer by pigi5 · Jan 16, 2011 at 04:51 AM
That was the original, sorry, the one I used was this:
var camera1 : Camera; var camera2 : Camera;
function Start () { camera1.enabled = true; camera2.enabled = false; }
function OnMouseUp () { if (camera1.enabled == true){ camera1.enabled = false; camera2.enabled = true; } if (camera2.enabled == true){ camera1.enabled = true; camera2.enabled = false; }
}