Question by 
               ChristianBlandford · May 05, 2014 at 04:56 PM · 
                javascriptarrow-keys  
              
 
              Switching camera code not working
I have a code to switch cameras when you press the arrow left, it takes you to camera 2, and when you press the right again, it takes you to camera 1.
it doesn't work when you press the right arrow? why??
 var Camera1 : GameObject;
 var Camera2 : GameObject;
 
 function Start(){
     Camera1.active = true;
      Camera2.active = false;
 }
 
 function Update(){
       if ( Input.GetKey(KeyCode.LeftArrow)){
     Camera1.active = false;
     Camera2.active = true;
        if ( Input.GetKey(KeyCode.RightArrow)){
       Camera1.active = true;
        Camera2.active = false;
         }
     }
 }
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by ChristianBlandford · Dec 30, 2015 at 01:54 PM
Turns Out Unity Didn't like The Actual number 1 in the variable, so i had to do it like "CameraOne"
Doh
Answer by Swaggre · May 06, 2014 at 07:06 PM
Do
 Camera1.SetActive(true);
And so on
no, it still doesn't work when i press the right arrow
Answer by KelvinWright · Dec 30, 2015 at 03:36 PM
 var Camera1 : GameObject;
 var Camera2 : GameObject;
 var CamSwitch  = false;
 
 function Update()
 {
     if(Input.GetKey(KeyCode.LeftArrow))
     {
         CamSwitch = true;
     }
     if(Input.GetKey(KeyCode.RightArrow))
     {
         CamSwitch = false;
     }
     if(CamSwitch  == true)
     {
         Camera1.SetActive(false);
         Camera2.SetActive(true);
     }
     if(CamSwitch == false)
     {
         Camera1.SetActive(true);
         Camera2.SetActive(false);
     }
 
 }
Your answer
 
 
             Follow this Question
Related Questions
Speed Increase Power up 1 Answer
what does this error mean? javascript 0 Answers
Tree Chopping/Harvesting cooldown 0 Answers
Any way to use UI on a screen renderer? 0 Answers
Please help me with my mouse pointer 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                