- Home /
Punch Animation Doesn't Work And Others Do...
This is my script, javascript (I'm using mecanim):
if (Input.GetButton("Fire1"))
{
punch = true;
if (punch == true)
{
animator.SetBool("Punch", true);
}
}
if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.LeftShift))
{
sprint = true;
if (sprint == true)
{
animator.SetBool("Sprint", true);
}
}
if (Input.GetKey(KeyCode.W))
{
run = true;
if (run == true)
{
animator.SetBool("Run", true);
}
}
else
{
animator.SetBool("Run", false);
animator.SetBool("Sprint", false);
animator.SetBool("Punch", false);
}
There's nothing wrong with the variables, as they're all fine. For some reason all the animations work except for the punch animation. The punch animation only works when I'm running... it's not to do with "Fire1" either, I've checked and fire1 is the left mouse button. I've tried doing Input.GetMouseButtonDown(0)
and the same thing happened as with fire1. Please can someone find a solution to this please!
when I click left click, punch does become true, but doesn't play the animation.
comment this line like //animator.SetBool("Punch", false); and test
You have to follow your game play logic (when) to stop punching. $$anonymous$$y suggestion would be use an IEnumerator function to stop punching after x secs(say)
could I just make a function that when punch is true doesn yield WaitForSeconds(amount of seconds that the animation is), then make punch false, would that work? and what's IEnumerator?
Answer by Sundar · Dec 19, 2013 at 06:57 PM
Its not complicated, try this
if (Input.GetButton("Fire1"))
{
punch = true;
if (punch)
{
animator.SetBool("Punch", true);
StartCoroutine(StopPunch(2.0));
}
}
function StopPunch (waitTime : float) {
yield WaitForSeconds (waitTime);
animator.SetBool("Punch", false);
}
Thanks a lot for your help, this was an annoying thing in my game and now it works! I appreciate the help :D
Your answer
Follow this Question
Related Questions
Animation play when dead 2 Answers
Java Script: Clock script help. 1 Answer
Animation Script not working. 1 Answer
Animation Script Error 1 Answer