Hello, this may sound like a newbie question. Im looking to put a gui label ontop of a gui texture and was wondering how can I go about approaching this via javascript? I tried searching for a solution but could not find one. Any help to lead me in the right direction is appreciated. Thanks.
in my opinion you should not mix the ongui and guitext(ure) stuff. you can also use a label to display a texture and then use it again at the same coordinates with the text you want to display.
@exiguous The text I want to display is not in the same coordinates as the texture. Its aligned different coordinates yet still ontop of texture on the bottom right. Im basically displaying amount of bullets and clip size ontop (in text) of the equipped weapon gui.texture. @TheRaider If worse comes to worst Ill have to do this but I was hoping to avoid it because it will require me to change the structure of allot of code just to make something simple like this happen. Right now im wondering if there is any way to tell the gui.label rect to display ontop of everything? thus making it ontop of the gui.texture almost like a layer.
well im wondering if i can tell a gui.label to display above a gui.texture via code like a layer or alpha channel of some sort. the gui texture is like this: GUI.DrawTexture (new Rect (Screen.width + 8 - (Screen.width/12.5), 30, 88, 87),WeaponHud); the gui labels i want displayed above it like a layer is like this: GUI.Label (new Rect (Screen.width - (Screen.width/15),50,200,80),"" + bulletsLeft, style1); GUI.Label (new Rect (Screen.width - (Screen.width/16.5),50,200,80)," | " + magazines);
There are several different ways you could do this. One is to use GUI Groups: Code (csharp): var hudPos : Rect; var hudImage : Texture2D; var bulletsLeft = 6; var magazines = 2; function OnGUI(){ GUI.BeginGroup(hudPos, hudImage); GUI.Label(Rect(10,10,200,80),bulletsLeft.ToString()); GUI.Label(Rect(10,100,200,80)," | " + magazines); GUI.EndGroup(); } Another is to use a GUIStyle: Code (csharp): var hudPos : Rect; var hudGUI : GUIStyle; var bulletsLeft = 6; var magazines = 2; function OnGUI(){ GUI.Label(Rect(10,10,200,80), "" + bulletsLeft + "\n| " + magazines, hudGUI); } Note that I combined both labels into one and added "\n" to make sure magazines appears on a second line. You'll add your hud image to the GUIStyle itself (Normal > Background), and you can alter the Font, Alignment, and Content Offset as needed to make your text look better.
Thanks allot tonyd, this was definitely some very helpful information. I ended up using the gui groups and called the weapon hud texture image from a variable stored in a different script for the background. So I didn't have to change much of my code to make it all work properly all thanks to your examples. Thanks again!