- Home /
how can i check when animation EXACTLY start and end in c# script using mecanim?
like the title says:
if (\\animation started) { }
and
if (\\animation ended) { }
Answer by unidad2pete · Aug 23, 2017 at 02:15 AM
The most exactly is make an animation event at first and last frame. But if animation have loop, thats events are called every time the frame is reached, but is easy to check on the function called if is a loop call or not.
If the animation has been created by yourself, on the animation windows you can see this icon to add new Animation event on any frame you want
First, your object need to have a Script with the function you need to call, We have this function.
public bool endFrame = false;
public void AnimationFrame()
{
if (endFrame)
{
endFrame = false;
print("Animation End");
} else
{
endFrame = true;
print("Animation Started");
}
}
If the object with the animation have the script whit the function attached, when you select the animation event on your animation window, you can select the function on the list.
If your animation its imported you can do the same on import settings, animation, select the animation and go to Events.
Add your event, called AnimationFrame without " () " and select your script on the Object menu ( you can see " Object none")
the bool variable for the example is only for the example, if your animator changes de animation and returns, the print info will be not correct. Only makes 2 functions, the first event calling the first function y the last event calling other function