- Home /
How do I keep a Custom Cursor (GUITexture) on top of UnityGUI controls?
How do I keep a Custom Cursor (GUITexture) on top of UnityGUI controls?
I've tried using layers with the cursor layer the highest Depth number on its camera, but my GUITexture is still underneath the control, box, lable, whatever
thanks
Answer by equalsequals · Jul 15, 2010 at 07:43 PM
UnityGUI is drawn last of all. Because of this there is no way to get anything outside of UnityGUI to draw on top of your UnityGUI.
My suggestion to you is to use OnGUI to draw your custom cursor using GUI.DrawTexture().
Hope that helps.
==
I tried DrawTexture and several other controls- they still draw under the existing GUI.Labels
How is the draw order controled?
GUI is immediate-mode and so it is drawn procedurally. The first draw command is on the bottom and the last is on the top. If your GUI draw calls are spread across multiple scripts you need to figure out which one executes last of all and at the end of that script is where you draw your custom cursor.
Thanks, I did try moving the cursor texture to the script where the label and boxes are, but although it works nicely over the labels, the boxes flicker badly when it is on top of them - seems odd
ok, I think I know what the problem is- The text should appear when the 3D object has mouse enter and disappear on mouse exit. I'm guessing when the box control comes on and they are both over the 3D object, it blocks mouse-overs by forcing a mouse exit- and turns itself off, so now I get another mouse enter to turn it on again- result, flicker.
I can make my Label look like a box, though, so it looks like I have a solution :)
Answer by 5seaton4 · May 06, 2011 at 03:41 AM
go into your script and in the OnGUI method type GUI.depth = 0; "0" being it gets shown on top of all things. hope this helped.
Your answer
![](https://koobas.hobune.stream/wayback/20220613064858im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How Do I Lock the Cursor to the Center of the Screen? 1 Answer
cursor misbehaves in the UI 0 Answers
How to make custom cursors work without enabling "Run in Background"? 1 Answer
Cursor / MouseOver Glitch 0 Answers
Glue mouse to object 2 Answers