Enemy healthbar script

Hello Unity Community, i’ve been lookin all over the web for an enemy healthbar that are not a GUI Texture or is only shown near the enemy.

the Healthbar should be above the enemy head within the game
or placed on the screen as a GUI when near the enemy

Any suggestions on how? or where i might find a tutorial?

Heres the Enemy Health Javascript:

#pragma strict

var Health = 100;
var Enemy : GameObject;
var Die : AudioClip;
//var DieAnimation : AnimationClip;

function Update ()
{
	if(Health <= 0)
	{
		Dead();
	}
}

function ApplyDammage (TheDammage : int)
{
	Health -= TheDammage;
}

function Dead()
{
	//animation.Play("DieAnimation");
	audio.PlayOneShot(Die);
	Destroy (gameObject, 1);
}

Thanks in advance

Would it make sense to make the GUI Bar you have as a child of the enemy in the hierarchy pane?

Position it where you want, then wherever the enemy moves, the bar will follow.

I found an even more simple solution by using a plane like this:

    #pragma strict
    
    var HealthBar : Transform;
    private var MaxHealth : float = 100;
    private var MaxBar : float = 0.2;
    var Health = 100;
	var Enemy : GameObject;
	var Die : AudioClip;
	var EnemyDoll : Transform;
	//var DieAnimation : AnimationClip;
     
	function Update()
    {
    // --- Change Size Of Bar --- \\
    transform.localScale.z = (MaxBar) * (Health/MaxHealth);
     
    // --- Change Colour Of Bar --- \\
    if(transform.localScale.z == 0.5)
    {
    transform.renderer.material.color = Color.green;
    }
    if(transform.localScale.z <= 0.35)
    {
    transform.renderer.material.color = Color.yellow;
    }
    if(transform.localScale.z <= 0.1)
    {
    transform.renderer.material.color = Color.red;
    }
	if(Health <= 0)
	{
	Dead();
	}
}
function ApplyDammage (TheDammage : int)
{
	Health -= TheDammage;
}

function Dead()
{
	//animation.Play("DieAnimation");
	audio.PlayOneShot(Die);
	EnemyDoll.animation.Play("Enemy die");
	Destroy (Enemy, 1);
}

But thanks anyways ^^