- Home /
Call a function dependent on frame of animation?
Basically, I have an attack function, and if I call it the same time I play the attack animation, the damage happens at the start of the animation, not when it looks like the sword hits him.
I've tried using animation.time, but this seems buggy, because sometimes the function gets called twice, sometimes it doesn't at all, so it does twice the damage or it does none sometimes.
Is there A better way I can call the function dependent on the player's animation?
I guess because I don't know how! Would you be able to explain how I would get this to work? And would I be able to use this method if the player can equip different weapons?
Answer by Jamora · Jun 20, 2013 at 05:51 PM
It is possible to call a function on a specified frame of an animation.
Have a look at AnimationEvent
ahh this works perfectly, thanks! Is there a way I can change the paramater of the function through script somehow?
what if the animation was imported from blender?
in my case it doesnt display in the animation panel for editing...
Answer by FlaSh-G · Jun 20, 2013 at 05:53 PM
You can add an Event to a certain animation frame with the Unity Animation Editor. It's simply a function call to attached scripts at the given time. The button for that is just aside the add keyframe button.
Note that if you're using $$anonymous$$ecanim (versus the legacy animation system), animation events aren't supported, but there's a third-party Event System for $$anonymous$$ecanim.
Your answer
Follow this Question
Related Questions
please help with my melee attack animation 1 Answer
Determine in which frame is an Animation currently 2 Answers
Cannot select function for Animation Event 0 Answers
Left can Animate but right cannot. Why? 0 Answers
How to make player attack animation play through without holding down a key. 0 Answers