GUI Text overlapping GUI Texture

Hi,
I’m trying to make a script that with a GUI Text overlapping a GUI Texture.

When the player hit the trigger I want a GUI Texture to apear as a background and I want the GUI Text to overlap the GUI Texture. But as it is now, I can only se the GUI texture. The GUI Text seem to be hidden behind the GUI Texture.

Here’s my code:

var myGui: GUITexture;
var myGui2: GUIText;

function OnTriggerEnter ()
{
    myGui.active = true;
    myGui2.active = true;
}

The GUI Texture has this script attached:

var texture : Texture2D;

function OnGUI()
{
    GUI.DrawTexture(Rect(0.0f, 0.0f, Screen.width, Screen.height), texture);
}

Any ideas? I have tried changing the z position of the GUI Texture, but I really know how to do it.

bump!

GUI can be a pain with level order. The basis with it is that the last thing called should be drawn ontop of all else.

Other then that you can try BringWindowToFront(1); or GUI.Depth = 0;

The GUI.Depth worked for my GUITexture. Which I used for my Inventory System… Where you pick up the Texture and move the item around. If I removed the Depth it goes behind all windows.

Here’s and example if you needed to know where to put it.

var texture : Texture2D;

function OnGUI()
{
    GUI.Depth = 0;
    GUI.DrawTexture(Rect(0.0f, 0.0f, Screen.width, Screen.height), texture);
}

Thank you for your reply. I tried to add depth set to 0 but it didn’t work. Maybe I need to set the the Gui Text depth = 1 but I have no idea how. Have tried several times but I just can’t get it to work.

First, GUITexture/GUIText and OnGUI code are two different things. They don’t mix; either use one or the other. With GUIText/GUITexture, the Z transform position controls the depth. With OnGUI code, depth is controlled by two things: code execution order within the same script, and GUI.depth with multiple scripts.

–Eric

Thank you for clearing that up. But I still don’t know how to solve my problem. Can I somehow draw the GUI Texture and GUI Text in the same script?