- Home /
Applying Damage To A Player Objects From An NPC
Hello,
I am making a TD game and will be having several different NPCs applying damage to player objects when they are attacking. My NPCs have different animation speeds; so is there a way to apply damage only when the animation has gotten to its last frame? Or if you can suggest a better way for me to do this then please, fire away ^_^
Thanks.
Answer by Pandiux · Sep 29, 2012 at 11:22 AM
Well you could use an AnimationEvent http://docs.unity3d.com/Documentation/Components/animeditor-AnimationEvents.html , and set it to your last frame, then you call the function AttackPlayer() in your NPC, and of course you already have a target in your script so no need to pass an argument in the function. Good Luck
I can't edit the animation (I paid for the asset and animations), it is ready only. I have no modelling skills at all so any kind of editing of the asset/animation in that sense is out of the window >.<*
I tried to get the animation length and Unity printed that it 0.6666667. Is there any way I can work with this ins$$anonymous$$d?
Ohh Sure, you just copy (duplicate) the read only animation and the duplicate will be writable, here is a Unity Answers question were it is explained how to http://answers.unity3d.com/questions/8172/how-to-add-new-curves-or-animation-events-to-an-im.html
I seem to be a bit of an idiot at this but it clearly is a good way of doing it. Thanks for helping =]
Your answer
![](https://koobas.hobune.stream/wayback/20220613081635im_/https://answers.unity.com/themes/thub/images/avi.jpg)