- Home /
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.
Answer by Grady · Jun 17, 2012 at 08:29 AM
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
Your answer
Follow this Question
Related Questions
Fps Controller fixed object (Gun) (Solved) 1 Answer
Animation & Script Help 2 Answers
Aiming down a gun 4 Answers
Camera Recoil,Please help me. 2 Answers