Changing variable value from Mecanim?

Hello, I’m new to Unity and Mecanim and I’m curious about some things in Mecanim. Is it possible to change one of the parameters within Mecanim? Or what is the best way to achieve following:

  • I have two states: idle and zapping
  • I want to activate zapping, so I have a bool parameter “Zap”
  • I also have an animation the length of 0.5s after which it goes back to idle
  • Zap is still true! And the animation’s stuck on loop.

What is the correct way to handle this - i.e. make sure that this is only fired once AND how do I attach some form of script trigger to the completion of the animation?

Just found out about “Triggers”. Figures.

You set parameters in the Animator with SetFloat, SetBool, SetInteger etc., and you retrieve the current value of any parameters with GetFloat, GetBool, GetInteger, depending on the type of parameter: Unity - Scripting API: Animator

In your case SetBool("Zap", true); will tell the Animator to transition to the Zapping state. If you want “Zap” to automatically uncheck itself after transition then you should use a “Trigger” parameter and call SetTrigger("Zap"); instead. However, I’ve personally found this to be somewhat unreliable, and prefer to manually unset my parameters in, say, LateUpdate() instead after I know the transition has occurred.