I have a problem with implementing a health and death system, help?

Ok, so I am designing a basic game that has creatures chasing you, and you have to jump to dodge them. The creatures are suppose to damage the player when they come into contact with the player, and after ten or so hits, the player dies. I am new to Unity, and have a very limited knowledge on JavaScript. All my code is in JavaScript, so keep that in mind. I have tried all the scripts I wrote, and all the ones I could find on the internet. What I really need is a simple mesh colliding damage system, with health and damage displayed as a variable. The script that I wrote at the start was a single code, applied to the player, and having the variables of “what mesh would cause damage on collision”, “health of player”, and “damage caused by a single collision of said mesh” (not in those exact words). Can you tell me how you would do it, if I was on the right track, and any tips and tricks involving this sort of collision problem. I want to learn how to do this, so If anyone does post code, add captions to show what each line does.

-Thanks

Try this out. Be sure that your character has an extra collider on it set to trigger then make sure your enemy has a rigidbody and this should work. If you have any problems I will help you :slight_smile:

var PlayerHealth : int = 100;
var MaxPlayerHealth : int = 100;
var DeathAnimaton : String;
var CurrentLevel : String;
        
function Start ()
{
    PlayerHealth = MaxPlayerHealth;
}
        
function Update ()
{
    if(PlayerHealth >= MaxPlayerHealth){
        PlayerHealth = MaxPlayerHealth;
    }
        
    if(PlayerHealth <= 0){
        PlayerHealth = 0;
        animation.Play(DeathAnimation);
        Application.LoadLevel(CurrentLevel);
    }
}
        
function OnTriggerEnter (other : Collider)
{
    PlayerHealth = PlayerHealth - 10;
}