- Home /
Character and enemy don't damage each other
Hi everyone, I am trying to make my character and enemy damage each other but everytime I go to play mode, all they do is play an animation of attacking. How can I make them lose health? And by the way, i have some codes for them losing health but they dont.
show us the code so we can help you. On the right click on Unity Answers tutorial video. Learn how to ask the question first..
First, you need a class to store player health. Second, you may have damaging mechanism based either on physical collision of objects or calculate it mathematically. In case of collision, use OnTriggerEnter() to check for collision between animated objects. Otherwise you can check the distance between two characters and if the distance is less that specific value and animation is being played, decrease the health. That's generally all.
Leave it as it is and call it pacifist wars. This gives you time to work it out and prompt people to buy the Pro version in which you can Actually attack each other :)
Yes, we have already considered this :P
Just saying but i was using a tutorial and it didn't really explain what the codes meant. So does dmg need to be defined. And just saying again i am 12 yrs old.
Answer by Jasper1900 · Oct 18, 2013 at 10:08 AM
You should first make a script with a variable Health. Now you can script it so when the collider of the weapon collides with the enemy/player, or when the animation is played, the health variable is reduced by the damage.
Your answer
Follow this Question
Related Questions
problem with the jump code.. 1 Answer
Search children first hierachy 1 Answer
Scripts Won't Update? 0 Answers
How to watch variables from another script efficiently? 1 Answer