I am using this script on a character to have an enemy apply damage to the character.
var maximumhitPoints = 100;
var hitPoints= 100;
function ApplyDamage (damage:float) {
if (hitPoints < 0)
return;
//apply damage
hitPoints --;
if (hitPoints <= 0)
Die();
}
function Die() {
if (hitPoints <=0)
//insert GUI here
}
but I'm having trouble understanding how to do GUI. All I want is for a window to pop up when you die that says you died and you can click an ok button. is this:
`static function Window (id : int, clientRect : Rect, func : WindowFunction, content : GUIContent) : Rect`
If you want to write a GUI in code it should be done in the function OnGUI(), you can't write GUI code inside one of your own functions. In your case you could use a boolean to check if a player is dead or not, like so:
var isDead = false;
function OnGUI()
{
if (isDead)
{
GUI.Box(Rect(left, top, width, height), "You're dead");
if(GUI.Button(Rect(left, top, width, height), "Click here"))
{
isDead = false;
}
}
}
function die()
{
if(hitpoints <= 0)
isDead=true;
}
if(boxselecting){
var width : int = leftupbox.x - rightdownbox.x;
var height : int = (Screen.height - leftupbox.y) - (Screen.height - rightdownbox.y);
var rect : Rect = Rect(rightdownbox.x, Screen.height - rightdownbox.y, width,