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.
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.
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
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*)]);*
*}*
*}*
*}*
*```*
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.
Yes simply like this:
GUI.DrawTexture(new Rect(40,40,98,100), texture);
GUI.Label(new Rect(68,72,80,20),"Text");