5
\$\begingroup\$

I have a GameObject "enemy" with an Animator and several states, like "idle", "walk", and "attack".

I want to activate the "hitbox" when an animation "attack" starts. The problems is that the sword does not fall down immediately: it takes about 2 frames.

Is there a way to know what frame of the animation is currently being run?

\$\endgroup\$
6
\$\begingroup\$

If you open the Animation Window (Window->Animation) and select your enemy GameObject, you can insert events for certain key frames by right clicking beneath the timeline (yellow marked area).

enter image description here

You can specify your own callback for this event, which has to be a function, available on your enemy. This will then be called, whenever this keyframe is being played.

\$\endgroup\$
  • \$\begingroup\$ Isn't this the old animation system? \$\endgroup\$ – Ben Oct 8 '15 at 2:52
  • \$\begingroup\$ @Ben This screenshot was taken from Unity 5.2 and this is the only way that I am aware of. I'm not very familiar with the whole animation system however. \$\endgroup\$ – user000user Oct 8 '15 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.