- Home /
Problem with Camera switching script
I'm trying to write a script that will switch cameras and back again on mouse click. At the moment, it only switches once. What should I do to make it switch multiple times?
var walking = true;
var camera1 : Camera;
var camera2 : Camera;
function Update () {
if(Input.GetButtonDown("Fire1") && walking == true){
change1();
}
if(Input.GetButtonDown("Fire1") && walking == false){
change2();
}
}
function change1 (){
camera1.camera.active = true;
camera2.camera.active = false;
walking = false;
print ("Switch1");
}
function change2 (){
camera1.camera.active = false;
camera2.camera.active = true;
walking = true;
print ("Switch2");
}
just a guess but try to move the true above the false and see if that does anything for you.
in function change2, you said it switches once, in function 1 you have true above false.
Answer by Dylan Cristy · Jun 01, 2011 at 08:29 PM
Without actually having tested this script, first thing I'd say to try is to simplify the if statements in Update(), like this:
function Update ()
{
if (Input.GetButtonDown("Fire1")
{
if (walking) change1();
else change2();
}
}
also, possibly change camera.active
to camera.enabled
.
Answer by jpdavis81 · Jun 01, 2011 at 08:55 PM
I agree, I dealt with this in the past as well and changing "active" to "enabled" fixed it for me.
Your answer
Follow this Question
Related Questions
How to use 2 Cameras in FPS 2 Answers
changing camera views 1 Answer
Run a simultaneous "viewer" build. 0 Answers
Shaders: How to ztest against specific layers? 1 Answer
Difference between OnWillRenderObject and OnRenderObject 1 Answer