Player Healt and demage.

Hi, I am tring to make health to my player but I don’t know how…
I found this script:

var health : float = 100;

function ApplyDamage( amount : float ){

health -= amount;

if ( health <= 0 ) Dead(); 


function Dead() {

print ( name + " is dead now.");


But now I need to make my player loose healt like If player hits gameobject"enemy" loose 10 healt…Does anybody know how to do this???

Add some combination of Rigid Bodies and/or Colliders.

In OnTriggerEnter() or OnCollisionEnter() call ApplyDamage(10) on the player’s game object.

Also, it’s “health” not “healt” and “lose” not “loose.”

As @kevork suggested, you can add this function at your script:

function OnCollisionEnter (theCollision : Collision) {
    if (theCollision.gameObject.tag=="Enemy"){

If your enemies have a tag "Enemy" assigned to them, the function above means: "if the player collides with an "Enemy", call ApplyDamage(10) (10 indicates the life that player will lose)" - what will follows is in the script that you have reported in the question!

Look at here for better explanations about onCollisionEnter:

As the link reports, "Note that collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached".

If you are not full-practiced with Unity's interface yet, and you don't know how to attach a rigidbody to an object, look at here: