- Home /
Call a function at a certain frame in animation without Animation Events?
Is there a way to call a function at a certain frame of a character's animation?
Pseudo-Example:
if (hero.animation("castingmagic").frame = 8)
SpawnFireBall();
I mainly want something like this for animations that take while to complete or have multple attack to execute the infliction only when the animation is in a particular frame?
Another psuedo-example:
if (hero.animation("flinching").lastframe)
NotFlinching();
Something like this would be helpful for my animations that are several frames long and I don't want the character to move until the end of the animation.
Answer by Bunny83 · Mar 21, 2011 at 02:13 AM
In short: No.
Animations are timebased in Unity. So there is no information about keyframes at runtime. Why don't you want to use Events?
The events are made For such things. Well, you can compare the current animation time if it's in a certain range but it would be a lot more work and it wouldn't be as reliable as animation events. If you want to know the exact (graphical-) frame when an animation has finished you would have to use ClampForever and stop the animation manually. Otherwise you will never reach the end of the animation.
It was mostly out of laziness. I was curious to see if it were possible without animation events, but I guess I can make a script at the area of the attack that does a Send$$anonymous$$essage() and have it toggle a flag or something...