- Home /
gun scope cam not working
I am starting a fps game. I am currently doing the scope part of a m4a1.
I made a cam for the scope called scopecam and a javascript called scope.
here is what it is inside the script:
     var Aim : boolean = false;
     
     var Cam : GameObject;
 
 function Update () {
 
 
         if (Input.GetMouseButtonDown(1)) {
 
             Aim = true;
         
             if (Aim == true) {
         
                 Cam.active = true;
         
         
         
             }
         
         if (Input.GetMouseButtonUp(1)) {
     
             Aim = true;
     
             if (Aim) {
     
                 Cam.active = false;
                 
             }
     
         }
     }
 }
I believe that 1 is for the right mouse, isnt it?
after that i have linked the script to the first person controller and the cam to the fp controller too.
I have also dragged the cam to the script where it says - cam: none(gameobject).
everything is ok until when i test the game, the scope is not responding.
thanks for the help!
Answer by chrisall76 · Oct 06, 2012 at 02:16 PM
Make sure that your also disabling the main camera when you scope, here's what I did:
 var ScopeToggle : boolean = false;
 var ScopeCam    : Camera;
 var GunCam      : Camera;    //I have a separate camera that renders my guns,
                              //You can set this to the main camera if you want
 
     if (Input.GetButton("Fire2")){ //Fire2 is the same as rightmouse
         ScopeToggle = true;
         
     }
     
     if (Input.GetButtonUp("Fire2")){
         ScopeToggle = false;
     }
     
     if (ScopeToggle){
         ScopeCam.gameObject.active = true;
         GunCam.gameObject.active = false;
     }
     
     if (!ScopeToggle){
         ScopeCam.gameObject.active = false;
         GunCam.gameObject.active = true;
     }
Answer by recondev · Oct 06, 2012 at 02:48 PM
it is still not working though? i've changed the main camera to GunCam, and changed my script to yours and nothing happened when i chick and hold the right mouse.
but thanks for the help
You've also added the scope cam to the scopecamera variable right?
like this?
var ScopeToggle : boolean = false; var ScopeCam : ScopeCamera; var GunCam : Camera; //I have a separate camera that renders my guns, //You can set this to the main camera if you want
 if (Input.GetButton("Fire2")){ //Fire2 is the same as rightmouse
     ScopeToggle = true;
 }
 if (Input.GetButtonUp("Fire2")){
     ScopeToggle = false;
 }
 if (ScopeToggle){
     ScopeCam.active = true;
     GunCam.active = false;
 }    
 if (!ScopeToggle){
     ScopeCam.active = false;
     GunCam.active = true;
 }
Answer by BasicGames · Nov 24, 2012 at 08:29 PM
By me the same, it aims the whole time if I select "scope toggle" if I deselect it there happens nothing :(
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                