- Home /
Best way to make melee AI damage player?
Hello Knights of unity Answers.
I have stumbled upon this kind of annoying problem with my AI. Everything is up and running fine, he chases the player until close enough to hit, then stands still and hits him, and if the player goes out of range again, he chases him again.
The only thing is, i can't figure out how to make him actually affect the 'health' variable on my player each time he plays the 'attack' animation, which is just about once every second. How would i go about with this?
Thanks in advance! Answers much appreciated.
Answer by screenname_taken · Jun 14, 2015 at 09:42 AM
Well you should put your damage scripts to make it easier, but you can write a function that causes damage to the player if it hits its collider, and place it in the object that has the animator component. Call it CauseDamage() for example. Then go to the animation clip that should do the damage and add an event to the frame that you'd like to cause the damage, and as an event add that function.
Answer by ESC-ESCAPE · Jun 14, 2015 at 10:28 AM
Type in google unity3d health bar and you will get tutorial.
Your answer
Follow this Question
Related Questions
Movement around a huge object by avoiding obstacles 1 Answer
Pause GameLoop with Pause Button 1 Answer
How to make WaitForSeconds work as a repeating/looping timer? 1 Answer
AI to make an object wander around and avoid obstacles? 5 Answers
Why isn't my simple coroutine working? (and how can I make it infinite?) 2 Answers