- Home /
This question was
closed May 25, 2014 at 11:54 AM by
CrilleStyles for the following reason:
I fixed it myself
This post has been wikified, any user with enough reputation can edit it.
Question by
CrilleStyles · May 25, 2014 at 11:10 AM ·
guihealth
If health lower than 0 display gui
How do I display gui saying "You died" If the health is lower than 0?
#pragma strict
var tex1 : Texture;
var tex2 : Texture;
var tex3 : Texture;
var tex4 : Texture;
var health : float = 100.0;
private var maxHealth : float = 100.0;
private var enterCollider : boolean = false;
//Damage Collider
function OnTriggerEnter (Col : Collider)
{
if(Col.gameObject.tag == "Player")
{
enterCollider = true;
Debug.Log("Is inside collider");
}
}
function OnTriggerExit (Col : Collider)
{
if(Col.gameObject.tag == "Player")
{
enterCollider = false;
}
}
function Update ()
{
//Health countdown whilst in the damage collider
if(health > 0 && enterCollider == true)
{
health -= Time.deltaTime * 20;
}
//Normal health regeneration
if(health >= 0 && enterCollider == false)
{
health += Time.deltaTime * 2;
}
//When health reaches 100, set to maxHealth
if(health > maxHealth)
{
health = maxHealth;
}
}
function OnGUI ()
{
if (health <= 100)
{
GUI.DrawTexture(Rect(0,0, Screen.width, Screen.height), tex1);
}
if (health <= 80)
{
GUI.DrawTexture(Rect(0,0, Screen.width, Screen.height), tex2);
}
if (health <= 40)
{
GUI.DrawTexture(Rect(0,0, Screen.width, Screen.height), tex3);
}
if (health <= 10)
{
GUI.DrawTexture(Rect(0,0, Screen.width, Screen.height), tex4);
}
}
Comment
add a 5th texture and add
if(health
at the end of the OnGUI() function ??