x


GUI.button order

I have this couples of repeatbuttons in one of my script. Whenever I click a button, the button will be able to drag.

My problem is whenever I dragged the button hovering other button, it's rendered behind the other buttons.

Here's how I render them

Code:
function OnGUI()
{
    for(var i = 0;i < transform.childCount; i++)
    {
       TogglePanel[i]    = GUI.RepeatButton (itemRect[i], "",

ItemPanel);

       if(TogglePanel[i])
       {

       if(!dragging)
       {
       dragging  = true;
       originPos = itemRect[i];
       }
       if(dragging)
       Dragging(i, originPos);
       }
    }

}

How do I set it so it's rendered on the top?

I need some help for this...thanks ^^

more ▼

asked Aug 25 '11 at 07:24 AM

beco13 gravatar image

beco13
26 11 12 14

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

There are two solutions based on where you draw your GUI.

On the right hand, you draw your GUI in one script, so the depth order is defined by the order of the call of GUI / GUILayout functions. To have a gui element draw over others, you should draw it at the end of your OnGUI method.

On the other hand, you draw your GUI with several scripts. You should consider using GUI.depth to order your gui through layers.

more ▼

answered Aug 25 '11 at 08:00 AM

fredpointzero gravatar image

fredpointzero
121 6 7 8

That a good solution of you :D

I don't want to do it for several scripts for now....Since it's been a hard work doing it in a script..hahahaha LOL

is there any idea how to draw it at the end? since all the buttons is not rendered separately but as a group...Do I need to rerender it at the end?

Aug 25 '11 at 09:24 AM beco13

dragging GUI elements can have some ugly sideeffects. Keep in mind that when you have overlapping buttons only the first one will react to the user input but it is drawn at the bottom. The last button is always on top of all others because unity draws the button in the order you call GUI.RepeatButton.

If you really want draggable GUI elements you should use a GUI.Window for each element. In a Window you can use GUI.DragWindow to drag the window ;)

windows can change their z-ordering automatically since Unity stores all GUI.Window calls internally and draw the windows right after OnGUI. Also the input is handled correctly when two or more windows are overlapping.

Aug 25 '11 at 09:58 AM Bunny83

@Bunny83 is right, you can use the native window system that support drag and drop, it will save you some coding time !

Aug 25 '11 at 11:01 AM fredpointzero
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3817
x3420
x820
x278

asked: Aug 25 '11 at 07:24 AM

Seen: 1495 times

Last Updated: Aug 25 '11 at 11:01 AM