Health UI Display

I’m setting up the UI to the health code

void OnGUI() {
		GUI.Label(new Rect(10, 10, 700, 40), "Health" + GetComponent<Health> Health);

	}

This is a separate script

#pragma strict

var MaxHealth = 100;
var Health : int;

function Start ()
{
	Health = MaxHealth;
}

function ApplyDammage (TheDammage : int)
{
	Health -= TheDammage;
	
	if(Health <= 0)
	{
		Dead();
	}
}

function Dead()
{
	RespawnMenuV2.playerIsDead = true; //VERY IMPORTANT! This line was added in tutorial number 19. If you haven't reached that tutorial yet, go ahead and remove it.
	Debug.Log("Player Died");
}

function RespawnStats ()
{
	Health = MaxHealth;
}

But there’s an error : error CS1525: Unexpected symbol `Health’ How can I fix that?

You are missing a ‘.’ in your GUI.Label before your variable Health. That line of code should be:

GUI.Label(new Rect(10, 10, 700, 40), "Health" + gameObject.GetComponent<Health>().Health);

Also just to make sure, you do know you are using a JS script (Health Script) and a C# script (The one where you are displaying the Health).

And also its better to cache the component reference rather than using GetComponent() every single frame.

You can also add a GUIText, you should put this script onto your player, then put the Health text as a variable: Such as this

var HealthCounter : GUIText;

function OnGUI () {
HealthCounter.text = "Health: " + Health.ToString();
}