- Home /
drawing GUIText on top of GUI.DrawTexture
Does anyone know how to make a GUIText object in my scene draw on top of Textures I'm drawing in the "OnGUI" function with GUI.DrawTexture? The text is always behind currently.
Thank you.
Answer by Mike 3 · Jul 29, 2010 at 08:50 AM
Pretty much no way to do it
It'd be doable if you rendered your GUIText to a rendertexture, then rendered that in the GUI above the desired item, but that's unity pro only, and a pretty dodgy workaround
Unfortunately its for iphone, so that wouldn't be practical. Is there an alternate to GUI.DrawTexture that could draw behind a GUIText object maybe? GUITexture perhapse? Thankyou.
Answer by Teagan · Aug 01, 2010 at 01:17 AM
I actually ended up just making a really quick score display, as thats all I needed it for. It just requires images 0 through 9 in the Resources folder.
//score object. public class ScoreDisplay { public static Texture2D[] numberTextures;
public ScoreDisplay() {
numberTextures = new Texture2D[10];
for (int x = 0; x < 10; x++) {
numberTextures[x] = (Texture2D)Resources.Load(x + "");
}
}
public void DrawText(Vector2 position, string score) {
for (int i = 0; i < score.Length; i++) {
GUI.DrawTexture(new Rect(position.x + 64 * i, position.y, 128, 128), numberTextures[int.Parse("" + score[i])]);
}
}
}
Answer by RGravity · Sep 20, 2012 at 10:05 AM
Render order for GUI elements is set by the z position of the transform. So in your case if you move the z position of the GUIText transform closer to the camera position than the other elements it will be drawn in front of them.
Answer by mbivol10 · Jun 17, 2015 at 03:20 AM
Yes simply like this:
GUI.DrawTexture(new Rect(40,40,98,100), texture);
GUI.Label(new Rect(68,72,80,20),"Text");