Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by klaus · Jun 08, 2010 at 06:39 AM · guimousecustomgui.depth

GUI with own mouse

Hi, I turned off the system mouse with

Screen.showCursor = false; 

and made my own mousepointer with a texture thats follow the mouse.

var mousePos : Vector3 = Input.mousePosition;
var pos : Rect = Rect(mousePos.x,Screen.height - mousePos.y,cursorImage.width,cursorImage.height);
GUI.Label(pos,cursorImage); 

But now, my mouse its behind all GUI elements. Is there something to put the mouse over the GUI?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by Eric5h5 · Jun 08, 2010 at 07:16 AM

Put the mouse cursor code in its own script, and set GUI.depth for that script so it's drawn first. By the way, you should use Event.current.mousePosition instead of Input.mousePosition. That way you don't have to translate between screen space and GUI space.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image qJake · Jun 08, 2010 at 08:09 AM 0
Share

Wow... all this time and I didn't know that property existed, heh... guess you learn something new every day ;)

avatar image e-bonneville · Feb 07, 2011 at 03:36 AM 0
Share

Haha, just came across that little beauty... fantastic.

avatar image blacksnow · Jan 21, 2012 at 05:29 AM 0
Share

i see .. that's why Input.mousePosition not give exact position

avatar image hedge500 · Nov 05, 2013 at 03:33 PM 0
Share

When I use Event.current.mousePosition when I move the mouse up, it ends up going down, and the same happens when I move down, and I have the same exact script as klaus. Left and right work just fine though.

avatar image
0

Answer by qJake · Jun 08, 2010 at 06:51 AM

Draw the mouse cursor last (or first), and make sure your GUI is all in one script. GUI is rendered in order of statement execution, so if it's behind everything else, put it at the opposite end of the script.

If you have multiple scripts that draw the GUI, unfortunately there's little you can do to control the order of script execution. From what I've read, it seems the script execution order is somewhat random, though you could try placing your script inside one of Unity's special folders, such as the Plugins/ folder. This MAY cause it to compile and run first, but I'm not sure, and I wouldn't bank on it.

Edit: As Eric said, you can also change the GUI.depth property to change the GUI layering.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by PaulUsul · Jun 08, 2010 at 10:34 AM

I have had little luck with depth, but windows work great for the cursor :)

GUI.Window((int)WindowsID.MouseCursor, cursorRect, DrawCursor, "", GUIStyle.none); GUI.BringWindowToFront((int)WindowsID.MouseCursor);

private void DrawCursor(int id) { GUI.DrawTexture(new Rect(0, 0, cursorRect.width, cursorRect.height), currentCursor, ScaleMode.ScaleToFit, true); }

Or else you could implement a GUI draw order script. Only thing is that you get all your OnGUI in one method, dunno if that is good or bad..

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Eric5h5 · Jun 08, 2010 at 04:11 PM 0
Share

GUI.depth works perfectly. If you're having problems, it's probably because you were trying to use it in the same OnGUI function in the same script, when in fact it's for use in different scripts.

avatar image PaulUsul · Jun 09, 2010 at 01:08 PM 0
Share

Argh perfect is a really big word or your new and you don't seem new. If you look at the "What's new in Unity 2.5" http://unity3d.com/unity/whats-new/unity-2.5 You'll see that under "Other Fixes:" it says "GUI.depth now works again".. soo whether it works, really depends on the version :P

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

custom mouse changing when hovering over objects 1 Answer

Rotating a GUI Object Based on Mouse Position with Locked Mouse 1 Answer

Using different custom inspectorscripts 1 Answer

Disable Selection on Left button Mouse Click 3 Answers

Show Gui button as hovered with custom mouse position 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges