hey guys i have added a dammage reciever to it (dammage Reciever) from the first person shooter is it possitble to lets say the shield hase 100% health at 100% to 75% texture 1 from 75%to 50% texture 2 and from 50% to 25% texture 3 texture 1 is a blue one stands for 100/75% texture 2 is a green one stands for 75/50% texture 3 is a red one stands for 50/25% i hope you get my drift
material mat1, mat2, mat3, mat4, mat5, matNone;
if shield_health == 100
do mat1
if shield_health <100 && > 75
do mat2
if shield_health <75 && > 50
do mat3
if shield_health <50 && > 25
do mat4
if shield_health <25 && > 1
do mat5
if shield_health <= 0
do matNone
Now fill it in with real scripting, and you be good =).
Justin showed a way but i like a more versatile approach:
// JS
var shildTextures : Texture2D[];
var health : float;
var healthDisplay : GUITexture;
function Update()
{
// get health as value between 0.0 and 1.0
var v : float = health / 100.0;
v *= shildTextures.length;
// this line will round it down to the next integer.
var index : int = v;
// make sure it doesn't get out of bounds
index = Mathf.Clamp(index,0,shildTextures.length);
// assign the selected texture
healthDisplay.texture = shildTextures[index];
}
This script can handle any amount of textures. If you want 4 textures (0-25, 25-50, 50-75, 75-100) just set the array in the inspector to 4 and assign your textures. Make sure the first texture is the 0-25 and the last one the 75-100.
If you provide only 3 textures it will split up like 0-33, 33-66, 66-100