Health Code Help

Hello, I am very new to programming and have recently enrolled in a game design course. I am attempting to place a health system, just a simple GUI text to my game, so that when the player is attacked by Zombies, he will lose health.

It’s a simple point and click game, and I have the GUI text show up, but the player does not lose lose health when attacked by the zombies.

As I said, I am very, very new to programming and most of my material I have learnt from tutorials online as we are on school holidays. Any assistance would be greatly appreciated.

My Code is attached. Thanks in advance.

#pragma strict
 
var health : int = 100;
var damage : int 10;
var Enemy :  GameObject;
var gos : GameObject[];
        gos = GameObject.FindGameObjectsWithTag("Enemy"); 
  
function Update () 
{
    if(health < 0)
    {
       Die();    
    }
}
 
function OnGUI ()
{   
    GUI.Box(Rect(10,Screen.height - 150, 200, 145), "");
    GUI.Label(Rect(20,Screen.height - 140, 180, 125), health + " / " + "100");
}
function OnTriggerEnter ( hit : Collider ) 
{
    Debug.Log("trigger");
    if(hit.gameObject.tag == "Enemy")
    {
	   Enemy = hit.gameObject;
       TakeDamage(); 
    }
    if(hit.gameObject.tag == "Enemy")
    {
       Enemy = hit.gameObject;
       TakeDamage(); 
    }
}
 
function TakeDamage()
{

}
 
function Die()
{
    Debug.Log("I'm dead");
    Network.Destroy(gameObject);

}

Well if damage intervals are in units of 10 you probably want “if(health<0)” to be <1. But this has nothing to do with the fact that nothing is happening.

With this logic, I am assuming that when you get close to the other object you want to take damage. Meaning you need something in TakeDamage() to decrement your health like
health = health - damage;

But maybe I don’t understand what your trying to accomplish.

did you forget to substract the damage?

function TakeDamage()
{
health-= damage; 
}

Hi louiedoggs!

Your TakeDamage function is empty.
Should be something like:

function TakeDamage()
{
    health -= damage;
}

Also, the function gets called twice from your OnTriggerEnter.