- Home /
Can I make my GUI Buttons appear OVER a GUI Window?
I think the question is pretty self explanatory. I have two buttons that appear at the cursor position when something else is right clicked (I'm using the Brackey's inventory system, C# edition). So when I click on an item in the inventory, I want the buttons to show up. And they do, but they show up underneath the inventory. I can still click them and everything, but that's not exactly what I want. I want the buttons appearing over the GUI window that is the inventory. Here is the script I'm using to make my buttons appear, in case that's important:
void OnGUI(){
if (askQuestion == true){
if (!mousePosHasBeenSet){
mousePos = Event.current.mousePosition;
mousePosHasBeenSet = true;
}
//Debug.Log ("askQuestion is " + askQuestion);
//GUI.Box(new Rect(mousePos.x, mousePos.y, 25, 25), questionToAsk);
//Debug.Log ("mouesPos y is " + mousePos.y);
//Debug.Log ("The real y mousePosition is " + Input.mousePosition.y);
if(GUI.Button(new Rect(mousePos.x, mousePos.y, 150, 20), yesString)){
selectedYes = true;
doDroppingOption ();
}
if(GUI.Button(new Rect(mousePos.x, mousePos.y + 20, 150, 20), noString)){
selectedYes = false;
doDroppingOption();
}
}
}
And here is a picture showing what I'm talking about:
Super big thanks to anybody who offers help! All I need is to get those buttons to appear OVER the inventory window (which is a GUI.Window), rather than under.
Answer by zharik86 · Jul 29, 2014 at 06:32 AM
As far as I understood, buttons shall be over all other GUI elements. For this purpose there are two methods. The first is to arrange your GUI elements in your one script. And the second is to use two scripts (or more) with the method GUI.depth which description you will find here.
Heck yeah! I swear I looked at all the documentation for GUI, I must have missed this one. Looking back at it now it seems pretty obvious. Thank you very much!
Your answer
Follow this Question
Related Questions
How to make GUI button glow 0 Answers
Change GUI.Button Texture on runtime 1 Answer
In game Escape menu displays all the time 1 Answer
Convert GUI Button to GUI Texture 0 Answers
GUIStyle not working on GUI.Button 4 Answers