How to set/reset a parameter at the end of animation?
I am transitioning between 2 animations using a parameter.
Animation A ----------set parametere to 1----------> Animation B
At the end of animation B, I want to go back to Animation A, and reset the parameter back to 0.
How would I do that?
Yes, it is 3D model. Animations are a part of .fbx files.
use triggers as parameters in transition A to B .And exit time in transition B to A. Animation A---Trigger(exit time off)---->Animation B---Exit Time---->Animation A
Answer by yaumito · Apr 30, 2020 at 04:50 PM
I may arrive here almost 4 years later, but I just found in some situations you can refocus this case by using Triggers instead of Booleans. A trigger is called only once, so in case you want to use a parameter to reset the boolean which called the animation state, you can control it in a really clean way.
Answer by JigneshKoradiya · Apr 07, 2016 at 06:26 PM
click on your fbx file and you found animation tab in inspector
select particular animation and than below that you found option event you can add event there and select which method you want to call from particular script
Answer by mattseaton22 · Jul 25, 2018 at 03:22 AM
I know this is an old question, but I was looking for a similar thing tonight. Of course there are various ways to accomplish this, but I wanted something simple and elegant. In the end I settled for this temporarily at least:
void Update ()
{
if (usingAbility)
{
usingAbility = false;
ResetAbilityState(); // The parameter is reset on the following frame
}
if (Input.GetAxis("Fire") > 0f)
{
usingAbility = true;
DoAbility(true, 1); //This function sets the animation parameter to 1.
}
}
I used a bool which is checked on the next frame and if true (i.e. the animation was triggered) the integer parameter is switched back to a default value. The animation will still play to completion but won't loop afterward.
Actually I found a better way. Use the State$$anonymous$$achineBehaviour class. It has callbacks that run when the animation ends (or starts, updates, etc.) and the callback gets a reference to the animator instance as one of its parameters, from which you can change parameters, grab the gameObject, etc.. You can attach this as a script to your animations, but I couldn't drag and drop it on. I had to hit the "Add behaviour" button in the inspector.
https://docs.unity3d.com/ScriptReference/State$$anonymous$$achineBehaviour.html