- Home /
Shield texture (multiple) textures
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
Answer by Justin Warner · May 09, 2011 at 12:55 PM
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 =).
just a small correction, ins$$anonymous$$d of if shield__health < x && > y it should be if(shield_health y)
That's pseudo code ;) "Now fill it in with real scripting"
Answer by Bunny83 · May 09, 2011 at 01:25 PM
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
Lol. I refuse to give people code if they haven't tried for themselves. They don't learn, then they come back, and expect more. Seen it many of times.
:D yeah, i know, usually i follow the same principles, but in the end it's not only an answer for him ;). The question is general enough for me.
Your answer
![](https://koobas.hobune.stream/wayback/20220613132903im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
TriPlanar Textures Not Working Properly 1 Answer
Most efficient way to create cubes with multiple textures 2 Answers
Baking multiple textures for Unity models workflow? 1 Answer
Multiple texture import settings? 2 Answers
How does the unity terrain shader handle an arbitrary amount of textures ? 1 Answer