Hey guys! I’m working on making a simple health bar, using the Texture Array example from the Lerpz tut, and it’s not working out for me, I believe the problem lies within my math but not sure why, here’s what I got:
var healthBarScale = Mathf.RoundToInt(health / maxHealth) * 100
GUI.Box(healthBarRect, GUIContent(healthBar[healthBarScale]), menuStyle);
Not sure what the prob is I’ve tried everything I can think of; health / (maxHealth * 100); just health/maxHealth, and multiplying healthBarScale by 100 both when I call the texture and by itself before I call it; nothing seems to work… much thanks!
I don’t know ‘what the prob is’ either, since you didn’t describe what’s happening. At a guess though, either healthBarScale is getting set to a value larger than the number of textures you have in healthBar, or healthBar isn’t set up correctly (doesn’t contain textures, has the same texture in every slot, or is otherwise not what you want, or healthBarRect is uninitialized / off the screen, or the code isn’t being executed at all, or…
Check all of those, and if that doesn’t turn up the problem, post back with details of what the problem actually is… 
Try:
var healthBarScale = Mathf.RoundToInt( (health / maxHealth) * 100);
Oops, I meant to cover that possibility too:
var healthBarScale = Mathf.RoundToInt((health / maxHealth) * 14);
(there could be only 14 elements in healthBar, right?) or, better,
var healthBarScale = Mathf.RoundToInt((health / maxHealth) * healthBar.Length);
Lol my bad, the problem is that it always shows the 0 picture. My texture array is set up correctly and has all images loaded in properly, and when I plug in my players current health it changes texture(albeit not to correct percentages) they all work. The problem seems to lie with the math.
I’ve tried all the answers you guys provided I’m gonna look in the alpha mask direction anyway, this was supposed to just be a quick solution so i could see it working, so i’m not concerned, it would just be nice to know WHY it didn’t work. Ahh well, thanks for the help guys!