- Home /
Is there a good technique to link script events to specific animation frames?
I basically want to draw hitboxes for a character based on what animation frame this character is in.
So if I had a 10 frame animation, each of those frames would draw a custom set of hitboxes and determine if any of the hitboxes have collided.
This is an example of what I would want the end result to look like, with the red circles being hitboxes: http://imgur.com/pksh4YU
Right now I have it set up so that mecanim handles animation transitions according to a controller script I wrote. The animator switches the animation when I change the state integer.
Is there a way to know what animation frame a gameobject with an attached animator is in? I was thinking of telling it to create boxes based off some coordinate info I would have set up, and handle all collision through scripting.
Answer by Lovelock · Oct 12, 2014 at 06:41 AM
Check out Animation Events as far as linking a script to a specific frame of animation.
Inside the Unity Animation editor you can right click above a frame and choose "Add Animation Event". It displays a list of public functions available on the selected game object. You can even pass in different parameters with each event.
As for updating the hitboxes based on the frame of the animation, check out the solution I posted in your other question. Enjoy!