Simple 2D Hero Controller Animation Question
The problem I'm running into is I'm only getting one animation to play on my hero on a keypress and it is whatever is before the else statement,
if (Input.GetKey(KeyCode.RightArrow))
{
anim.SetBool("LeftorRight",true);
anim.SetFloat("Speed",1f);
MoveRight();
}
if (Input.GetKey(KeyCode.LeftArrow))
{
anim.SetBool("LeftorRight",true);
anim.SetFloat("Speed",1f);
MoveLeft();
}
if (Input.GetKey(KeyCode.UpArrow))
{
anim.SetBool("Up",true);
anim.SetFloat("Speed",1f);
Moveup();
}
if (Input.GetKey(KeyCode.DownArrow))
{
anim.SetBool("Down", true);
anim.SetFloat("Speed",1f);
MoveDown();
}
else{
anim.SetBool("Up",false);
anim.SetBool("Down", false);
anim.SetBool("LeftorRight",false);
anim.SetFloat("Speed",0f);
}
}
and what I want to do obviously is have the other animations work as well. The keys work work because I am able to move the hero the only thing I am not able to do is play the animations 3 out of 4 animations
Answer by OctoMan · Oct 27, 2015 at 04:52 PM
Try to set all anim.setBool you don't need in the specific keypress to false.
if (Input.GetKey(KeyCode.UpArrow))
{
anim.SetBool("Up",true);
anim.SetBool("Down",false);
anim.SetBool("LeftorRight",false);
anim.SetFloat("Speed",1f);
Moveup();
}
if (Input.GetKey(KeyCode.DownArrow))
{
anim.SetBool("Down", true);
anim.SetBool("Up",false);
anim.SetBool("LeftorRight",false);
anim.SetFloat("Speed",1f);
MoveDown();
}
and so on.
I did what you said to do and it still has the same problem. Where the only animation that works correctly is the down animation. :(
then it's
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.RightArrow))
{
anim.SetBool("LeftorRight",true);
anim.SetFloat("Speed",1f);
$$anonymous$$oveRight();
}
else if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftArrow))
{
anim.SetBool("LeftorRight",true);
anim.SetFloat("Speed",1f);
$$anonymous$$oveLeft();
}
else if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.UpArrow))
{
anim.SetBool("Up",true);
anim.SetBool("Down",false);
anim.SetBool("LeftorRight",false);
anim.SetFloat("Speed",1f);
$$anonymous$$oveup();
}
else if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.DownArrow))
{
anim.SetBool("Down", true);
anim.SetBool("Up",false);
anim.SetBool("LeftorRight",false);
anim.SetFloat("Speed",1f);
$$anonymous$$oveDown();
}
else{
anim.SetBool("Up",false);
anim.SetBool("Down", false);
anim.SetBool("LeftorRight",false);
anim.SetFloat("Speed",0f);
}
Your answer
Follow this Question
Related Questions
How can i stop my shooting animation after playing? 0 Answers
Pausing and resuming animations Unity 5.2 0 Answers
Animation Running Game 0 Answers
Having problems with making a Navmesh Agent stop and play an attack animation 0 Answers
Why is my animation being started, but is not actually playing? 1 Answer