- Home /
How do I make certain GUI textures be in front of other GUI textures?
I have a health bar system and i need the health to be above the bar that it is in so that it appears as if the bar is slowly draining but for some reason it is behind I don't get this?
How do I make the health take preference over the bar in the GUI?
Answer by Mike 3 · Jan 07, 2011 at 10:14 PM
You can use the z position to set the rendering depth. The lower it is, the more in front it should be
tyvm didn't think it was so simple but it was thanks a ton
Answer by yoyo · Jan 07, 2011 at 10:52 PM
If your GUI textures are drawn from different components, you can also set GUI.depth in the various OnGUI() methods ... to make Component1 draw over top of Component2:
Component1:
void OnGUI() { GUI.depth = 1; ... }
Component2:
void OnGUI() { GUI.depth = 2; ... }
luckily $$anonymous$$e are all from the same component :) But thanks this answer will be helpful to people who's GUI textures are from different components, nice answer :)
In that case thanks for the upvote, but $$anonymous$$ike probably still deserves credit for the "right" answer :-)
Indeed - this is for OnGUI, not for GUITextures. Guess it depends which GUI Texture we're talking about :D
True, GUI.DrawTexture != GUITexture. Use GUI.depth for the one, and transform.z for the other. (Note that GUI.depth applies to everything drawn in your OnGUI routine.)