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\$
  • \$\begingroup\$ btw, you can omit == true and the behavior won't change \$\endgroup\$ – trollingchar Jul 23 at 13:51
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\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.