How to display Text using JavaScript ?

When I die I want to display message but It doesn’t work I have tried that:

Player Health:

#pragma strict

var MaxHealth = 100;
var Health : int;
var Text = "You Have Died !";

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

function Dead()
{
	RespawnMenuV2.playerIsDead = true;
	Debug.Log("Player Died");
	GUI.Label (Rect (10, 30, 1000, 20), "Game Over" +Text);
}

function RespawnStats ()
{
	Health = MaxHealth;
}

where I added this to display text:

var Text = "You Have Died !";

and

GUI.Label (Rect (10, 30, 1000, 20), "Game Over" +Text);

It’s still doesn’t work for me :confused:

That is respawn Script:

#pragma strict
var lookAround01 : MouseLook;
var lookAround02 : MouseLook;
var charController : CharacterController;

var respawnTransform : Transform;

static var playerIsDead = false;

function Start () 
{
	lookAround01 = gameObject.GetComponent(MouseLook);
	lookAround02 = GameObject.Find("MainCamera").GetComponent(MouseLook);
	charController = gameObject.GetComponent(CharacterController);
}

function Update ()
{
	if (playerIsDead == true)
	{
		lookAround01.enabled = false;
		lookAround02.enabled = false;
		charController.enabled = false;
		Screen.showCursor = true; }
	}


function OnGUI ()
{
	if (playerIsDead == true)
	{
		if (GUI.Button(Rect(Screen.width*0.5-50, 200-20, 100, 40), "Try Again"))
		{
			RespawnPlayer();
			Screen.showCursor = false; } 
		}
		
	
		}
	

function RespawnPlayer ()
{
	transform.position = respawnTransform.position;
	transform.rotation = respawnTransform.rotation;
	gameObject.SendMessage("RespawnStats");
	lookAround01.enabled = true;
	lookAround02.enabled = true;
	charController.enabled = true;
	playerIsDead = false;
	Debug.Log("Player has respawned");
}

@script RequireComponent(CharacterController)

Every Help appreciated

Thanks

You could use GUIText and setactive to false until you die then set it true.
Try adding this to your health script.

var GameOver : GameObject;

function Dead()
{
    RespawnMenuV2.playerIsDead = true;
    Debug.Log("Player Died");
    GameOver.gameObject.SetActive(true);
}

In the above you’ll add a game object with your text on it in the inspector and it’ll do the rest and then to make it (false) Add this to your respawn script.

var GameOver : GameObject;

function Start () 
{
    lookAround01 = gameObject.GetComponent(MouseLook);
    lookAround02 =   GameObject.Find("MainCamera").GetComponent(MouseLook);
    charController =   gameObject.GetComponent(CharacterController);
    GameOver.gameObject.SetActive(false);
}

function RespawnPlayer ()
{
    transform.position = respawnTransform.position;
    transform.rotation = respawnTransform.rotation;
    gameObject.SendMessage("RespawnStats");
    lookAround01.enabled = true;
    lookAround02.enabled = true;
    charController.enabled = true;
    playerIsDead = false;
    GameOver.gameObject.SetActive(false);
    Debug.Log("Player has respawned");
}

Can’t confirm is it works that way since I’m to lazy to check but I know that method works for me. xD Good luck