GUI newbie

Ive got an enemy game object and when it dies I want it to send a message to the GUI layer on my main character to say its dead, where shuld I start?

You don’t really send anything to the GUILayer directly.

If you meant GUITexture, then you need to use something like:

var goGUI: GUITexture = GameObject.Find("MainCharacter").GetComponent(GUITexture);

If not- use the built in GUI system inside Unity…
Lets say you display all your game GUI with a single script called DisplayGUI.js that is assigned to a game object called GameGUI.

Inside DisplayGui.js add:

private var bDisplayMessage: boolean = false;
private var strEnemyName: String;

function OnGUI()
{
   if (bDisplayMessage)
   {
      GUI.Label(Rect(Screen.width * 0.5 - 100, Screen.height * 0.5, 200, 50), strEnemyName + " just died!");
   }
}

function DisplayDeath(strName: String)
{
   strEnemyName = strName;
   bDisplayMessage = true;
   yield WaitForSeconds(5);
   bDisplayMessage = false;
}

Then, in the script that determines when you enemy dies add:

var gui: DisplayGUI = GameObject.Find("GameGUI").GetComponent(DisplayGUI);
gui.StartCoroutine(gui.DisplayDeath("Enemy01"));

This is a really simple (and wastefull) code, but it should get you started.
I didn’t have time to actually test this in unity, so if there’s a problem, let me know.

There appears to be a problem, startcoroutine is not a member of GUI…

Try:

function StartDisplay(strName: String)
{
   StartCoroutine(DisplayDeath(strName));
}
function DisplayDeath(strName: String) 
{ 
   strEnemyName = strName; 
   bDisplayMessage = true; 
   yield WaitForSeconds(5); 
   bDisplayMessage = false; 
}

and then:

var myGUI: DisplayGUI = GameObject.Find("GameGUI").GetComponent(DisplayGUI); 
myGUI.StartDisplay();