- Home /
If/Else Statement resulting in glitched animation.
I have a shield with two animations attached to it. One is for lifting the shield, and one is for lowering the shield. Clicking the left mouse button toggles this action. The following script proves unsuccessful, for when I click, the object seems to want to initiate both animations. This results in a mess of an animation that does not do what is intended.
#pragma strict
var mode: boolean = true;
function Start () {
animation.Stop("Shield");
animation.enabled = false;
collider.isTrigger = true;
}
function Update () {
if(Input.GetMouseButton(0)) {
hitmace();
}
}
function hitmace() {
var isblocking = mode == true;
collider.isTrigger = false;
animation.enabled = true;
if(isblocking) {
animation.Play("Shield2");
mode=false;
} else {
animation.Play("Shield");
mode=true;
}
collider.isTrigger = true;
}
Any help is appreciated, thank you.
Answer by robertbu · Aug 10, 2013 at 04:19 AM
You want to use Input.GetMouseButtonDown(0)
. Input.GetMouseButton(0)
, will return true for every frame the mouse is held down. GetMouseButtonDown(0)
will only return true for the frame the button went down.
Your answer
Follow this Question
Related Questions
Help playing the right animation 1 Answer
Visbility keyframes in animation 1 Answer
For loop has 'if-else' impossibility. 2 Answers
If \ Else how does the program reads it? 2 Answers