- Home /
And statement?
In my game I have a script that when I hit mouse 0 (left mouse button) I crouch using this script:
function Update () {
if(Input.GetKey("mouse 0")){
animation.Play("crouch");
}
}
And now when I hit left mouse button, I crouch, but now I want it so that I crouch and as I am crouching If I move forward I crouch walk (I have that animation) How would I do this? thanks!
Answer by Piflik · Jul 01, 2012 at 07:27 PM
Add a toggle that is set to true and test against it.
private var isCrouching : boolean = false;
function Update () {
if(Input.GetKey("mouse 0")) {
isCrouching = true;
animation.Play("crouch");
}
if(Input.GetKey("W") && isCrouching) {
animation.Play("crouchWalk");
}
}
While it might be tempting to nest the if(Input.Get$$anonymous$$ey("W")) inside the Input.Get$$anonymous$$ey("mouse 0") rather than creating a new isCrouching variable, just remember you can use the isCrouching elsewhere in the code, and you can also turn it into a toggle later if you want.
Your answer
Follow this Question
Related Questions
Black and White Visuals? 2 Answers
Crouch script problem! 1 Answer
Raycast problem trough the terrain 1 Answer
I am getting this error, why? 2 Answers
If \ Else how does the program reads it? 2 Answers