x


aim script error

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;

 }  

       }



}

}

this script don't work for me i press right button but when i relese it doesent change back.

more ▼

asked Jun 17 '12 at 07:41 AM

gannddan gravatar image

gannddan
0 1 1

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Ok, I just wrote this for you!

var origninalCam : Camera;
var aimCam : Camera;
private var originalCamActivated = true;

function Start(){
    originalCam.enabled = true;
    aimCam.enabled = false;

function Update(){

    if(Input.GetButtonDown("Fire2"){
       if(originalCamActivated == true){
         originalCam.enabled = false;
         aimCam.enabled = true;
         originalCamActivated = false;
       }
       else{
         aimcam.enabled = false;
         originalCam.enabled = true;
         originalCamActivated = true;
       }
    }
}

And please make sure to remember to format your code by selecting it all and pressing the 101010 button at the top next to the paperclip icon!

Now what you have to do, is drag your normal, starting camera into the originalCam variable, and the aiming camera into the aimCam variable.

Then, you're ready to go!

I think what you were lacking in your original script was the ability to detect what camera was currently enabled, and to then be able to switch back and forth!

I hope this works for you! If you have any more issues, then just let me know!!!!!

-Grady

more ▼

answered Jun 17 '12 at 08:29 AM

Grady gravatar image

Grady
1.1k 66 70 82

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3340
x1175
x446
x103
x31

asked: Jun 17 '12 at 07:41 AM

Seen: 462 times

Last Updated: Jun 17 '12 at 08:30 AM