|
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;
}
(comments are locked)
|
|
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.
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. Much Thnx. I found out before you replied but i never fought about dat. This is wot i did ... var aimCamera : Camera; function Update () { if(Input.GetButton ("Fire2")) { aimCamera.depth = 5; } else { aimCamera.depth = -20; } } because else basicly means if the above is not true then do this so basicly the same but different expression. Much Thnx
Jan 19 '11 at 07:46 PM
Kieran
(comments are locked)
|
