0
\$\begingroup\$

I want to make Unity play a squish animation when the player hits the ground, but only once, until the player jumps and hits the ground again, although Unity its constantly detecting that the player is on the ground and keeps playing the squish animation over and over again, only jumping stops it cause the condition to play the animation is if the player is on the ground. (loop already disabled) How I can possibly solve this?

 if (isGrounded == true)
        anim.SetTrigger("EnterGround");
\$\endgroup\$
1
  • \$\begingroup\$ btw, you can omit == true and the behavior won't change \$\endgroup\$ Jul 23, 2019 at 13:51

1 Answer 1

2
\$\begingroup\$

You need to store previous value of isGrounded. Change your code to this:

if (isGrounded && !wasGrounded) OnLanding ();
wasGrounded = isGrounded;

where wasGrounded is a boolean field and OnLanding is a method where you for example trigger animation.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .