var cam1 : Camera;
var cam2 : Camera;
function Start(){
cam1.enabled=true;
cam2.enabled=false;
}
function Update () {
if(Input.GetKeyDown(“1”)){
cam1.enabled=true;
cam2.enabled=false;
}
if(Input.GetKeyDown("2")){
cam1.enabled=false;
cam2.enabled=true;
}
}
my problem is that my projectile shoots when i click fire before i click cam 2
Use a boolean. Have it change depending on what button is pressed, and then make the rest of the code depend on the state of that boolean. so something like:
var cam1 : Camera;
var cam2 : Camera;
var isCam1 : boolean;
function Start(){
isCam1 = true;
cam1.enabled=true;
cam2.enabled=false;
}
function Update () {
if(Input.GetKeyDown("1")){
cam1.enabled=true;
cam2.enabled=false;
isCam1 = true;
}
if(Input.GetKeyDown("2")){
cam1.enabled=false;
cam2.enabled=true;
isCam1 = false;
}
//shooting code
if(isCam1){
//shooting code for camera 1
}
if(!isCam1){
//shooting code for camera 2
}
}