FPS Game - I am making an Aim System and need help (Calling all game scripters)

Basicly i need to make an aim system (looking down the sight of the gun). I think i have the the right idea in using a switch statement, but i'm not sure if the code is right or written right ...

Here is the code :

var aimCamera : Camera;

private var aim = false; private var pressedAimButton;

function Awake () { pressedAimButton = Input.GetAxis ("Fire2"); } function Update () { switch (pressedAimButton) { case true: aim = true; break;

    case false:
        aim = false;
        break;
}

if(aim) {
    aimCamera.depth = 5;
}
if(aim == false) {
    aimCamera.depth = -20;
}

}

That looks like one way to do it, but there is a better way. A switch is really not necessary here, particularly a two case switch, which is almost never preferable to a simple if statement. And even that is not necessary here. Let us use the Input object.

var aimCamera : Camera;

function Update(){
    if(Input.GetButtonDown("Fire2")){
        aimCamera.depth = 5;
        //anything else you want to have happen on aim button being pressed
    }
    if(Input.GetButtonUp("Fire2")){
        aimCamera.depth = -20;
        //anything else you want to have happen when aim is released
    }
}

Much cleaner, and more straightforward. If you so desire, the GetButtonDown and Up could be replaced with some comparisons with GetAxis, but I would not recommend it.