Quantcast
Channel: Answers for "How to add Player health and ability to take damage from a cube?"
Viewing all articles
Browse latest Browse all 4

Answer by daybson.paisante

$
0
0
Is impressive how people ask things so generic here. I mean... "How to receive damage?" You tell me, it's your game with your rules, you should be able to imagine them. Try to be more specific: "How comunicate between two scripts?" or "How show the damage received on a lifebar?" or "How detect the end of a collision?" This doubt is a very basic flaw in your coding skill, try start getting better on coding before learning Unity. Answer: You need to create your rule system. How much life the player has? How the damage is calculated: by weapon? by enemy? the player has an armor to defense himself? This is game design, and you need to have an ideia about how your game will be first. Supose that you have an Player with an armor, and an Enemy with an weapon, let's make the following: - Class name -> Player - Fields (define a value to each field as you want): - life -> int - maxLife -> int - minLife -> int - armor -> int - Class name -> Enemy - Fields - life -> int - maxLife -> int - minLife -> int - weapon -> damage Now you will check how [collision detection][1] works. And in the collision method you subtract the life by enemy weapon plus armor. This way your cube is receiving damage. But what goes when the life is zero? You will need to kill the cube, or do something else. [1]: http://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html

Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images