GUI: make texture visible/invisible?

Hey guys, I am still working on the FPS. And I am currently implementing a Bloodscreen (like in Call of Duty), so what I basically want, is that the Player will see Bloodscreen 1 (a .png texture) if his health is lower than 90, the second one if the player health is under 60 and the last one if the player health is less than 30 percent…
But I am not sure how to make it, I thought of setting the “a” color which is obviously the opacity to 0 and back to 255 if the case switches, however I don’t know how to do it exactly, and appreciate every helpful post from you! :slight_smile:
oh and btw, here’s the code which I already implemented, to show it “always”:

GUI.DrawTexture(Rect(0,0,Screen.width, Screen.height), Blood1, ScaleMode.StretchToFill, true);

(and this is working for all resolutions, perfectly, but still, it’s always there… kinda annoying :confused:

sincerely,

Cerbi

Here is an option with changing the alpha:

public var bloodTexture : Texture2D;

var currentHealth : int;
var MaxHealth : int;
private var currentAlpha : float = 1;

function Start()
{
	// This works only if you set the health before enabling this script
	// You can remove this line and set the MaxHealth on the inspector
	MaxHealth = currentHealth;
}

function Update()
{
	// Change the alpha values the way you like it
	if ( currentHealth >= 0.9*MaxHealth )
		currentAlpha = 0;
	else if ( currentHealth >= 0.6*MaxHealth )
		currentAlpha = 0.25;
	else if ( currentHealth >= 0.3*MaxHealth )
		currentAlpha = 0.5;
	else
		currentAlpha = 0.75;		
}

function OnGUI()
{
    var color = GUI.color;

	GUI.color.a = currentAlpha;
	GUI.DrawTexture(Rect(0,0,Screen.width, Screen.height), bloodTexture, ScaleMode.StretchToFill, true);

    GUI.color = color;

    // Now call more stuff
}