Hi,
I need help to finish my health script with GUI texture. I can’t see my GUI texture when I run the game. Also I want to be able to respawn in my game with a empty gameobject but I don’t know how. I already put my respawn variable.
static var healthcount :int = 100;
static var dead = false;
var health0 : Texture2D;
var health20 : Texture2D;
var health40 : Texture2D;
var health60 : Texture2D;
var health80 : Texture2D;
var health90 : Texture2D;
var respawn : Transform;
function Update ()
{
if(healthcount < 20)
{
GUI.Texture=health0;
}
if(healthcount < 40)
{
GUI.Texture=health20;
}
if(healthcount < 60)
{
GUI.Texture=health40;
}
if(healthcount < 80)
{
GUI.Texture=health60;
}
if(healthcount < 90)
{
GUI.Texture=health80;
}
if(healthcount < 100)
{
GUI.Texture=health90;
}
if(healthcount >= 100)
{
dead = true;
}
}
function LateUpdate()
{
if(dead = true)
{
}
}
Doing it that way isn’t very good.
Here, take a look at this.
Hi thanks for the message,
But I can’t see the thing that you want me to look.
heh, he didnt post any code.
A bit of cleaning up:
static var healthcount :int = 100;
var health0 : Texture2D;
var health20 : Texture2D;
var health40 : Texture2D;
var health60 : Texture2D;
var health80 : Texture2D;
var health90 : Texture2D;
var health100 : Texture2D;
var respawn : Transform;
private var texture : Texture2D;
function LateUpdate ()
{
texture = health100;
if(healthcount <= 90) texture=health90;
if(healthcount <= 80) texture=health80;
if(healthcount <= 60) texture=health60;
if(healthcount <= 40) texture=health40;
if(healthcount <= 20) texture=health20;
if(healthcount <= 0){
texture=health0;
}
}
function OnGUI() {
if(texture){
GUI.DrawTexture(Rect(10,10,texture.width,texture.height), texture);
}
}
thanks man,
That works perfectly but I just change
THIS: GUI.DrawTexture(Rect(10, 10, Screen.width, Screen.height), texture);
FOR THIS: GUI.DrawTexture(Rect(0.0f, 0.0f, Screen.width, Screen.height), texture);