- Home /
Question by
puyayavari · Jun 22, 2017 at 04:33 PM ·
animationanimatortransitionsstates
How can I make a state pass after a reversed state?
I want to play the walking animation when my character is walking and when he is pulled I want to stop walking animation play it reverse and when it reached the beginning of the animation I want it to pass to the PULLED state. But the problem is my animation keeps looping backwards and I guess I know the reason its because my next animation starts when this animation ends and when I play it reversed it never ends so the state never pass. WalkSpeed is not always 5 and it depends on the speed of the player and that causes the animation to be strate or reversed (can be less than 0) and BeingPulled becomes true as soon as my character is being pulled (as you can see in the code). How can I make a state pass after a reversed state?
public class RightAnimationController : MonoBehaviour {
private GameObject GameController;
private Statistics stats;
Animator anim;
// Use this for initialization
void Start ()
{
GameController = GameObject.FindWithTag("GameController");
anim = GetComponent<Animator>();
stats = GameController.GetComponent<Statistics>();
}
// Update is called once per frame
void Update ()
{
if (stats.SameSpeed)
{
anim.SetBool("Pulling", false);
anim.SetBool("BeingPulled", false);
anim.SetFloat("WalkSpeed", 0);
}else if(stats.RightFaster){
anim.SetBool("Pulling", true);
anim.SetBool("BeingPulled", false);
anim.SetFloat("WalkSpeed", stats.RightSpeed);
}else if (stats.LeftFaster){
anim.SetBool("Pulling", false);
anim.SetBool("BeingPulled", true);
anim.SetFloat("WalkSpeed", stats.RightSpeed);
}
}
}
unityquestion.png
(54.9 kB)
Comment