Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Blankzz · Jul 11, 2011 at 04:56 PM · guiscreenconvertpoint

ScreenToGUIPoint

Could somebody explain to me how I can convert a screenPoint to a GUIPoint. I've tried the GUIUtility.ScreenToGUIPoint but it doesn't seem to return what I want. Heres the testing code. The guiPoint remains the same as the screenPoint for some reason.

 Vector3 viewportPoint = new Vector3(1,1,1);
     Vector3 screenPoint = new Vector3(1,1,1);
     Vector2 guiPoint = new Vector2(0, 0);
 
     void OnGUI()
     {
         guiPoint = GUIUtility.ScreenToGUIPoint(new Vector2(screenPoint.x, screenPoint.y));
         
         GUILayout.BeginArea(new Rect(0, 0, 200, 200));
         GUILayout.Label("Viewport X: " + viewportPoint.x);
         GUILayout.Label("Viewport Y: " + viewportPoint.y);
         GUILayout.Label("Screen X: " + screenPoint.x);
         GUILayout.Label("Screen Y: " + screenPoint.y);
         GUILayout.Label("Gui X: " + guiPoint.x);
         GUILayout.Label("Gui Y: " + guiPoint.y);
         GUILayout.EndArea();
     }
 
     void OnMouseOver()
     {
         viewportPoint = transform.parent.camera.ScreenToViewportPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y,0));
         screenPoint = transform.parent.camera.ViewportToScreenPoint(viewportPoint);  
     }
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Eric5h5 · Jul 11, 2011 at 04:59 PM

 guiPoint = screenPoint;
 guiPoint.y = Screen.height-guiPoint.y;
Comment
Add comment · Show 3 · 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 TheMaster42 · May 16, 2013 at 08:00 PM 0
Share

I had the same problem. Does ScreenToGUIPoint just not work?

avatar image GODSBANE · May 16, 2013 at 09:13 PM 0
Share

@ The$$anonymous$$aster42: I used it in my code to get the position of the mouse on the screen. Here is the link to question which contains this code. http://answers.unity3d.com/questions/457737/mouse-screen-position-and-gui-position-not-scaled.html

avatar image VRARDAJ · Jun 28, 2020 at 05:41 AM 0
Share

I haven't tested this myself, but this appears to be caused by the the classic DX vs OpenGL pixel-read order. If you're rendering w/ DX10/11/12/etc. I think pixels are read from top to bottom, whereas if you're rendering in OpenGL, they're read from bottom to top. If this inversion is necessary still, it would prob be due to GUIUtility assu$$anonymous$$g one one render path while you're using the other. Not sure which, but if anyone else runs into this, try switching from DX to OpenGLor vice versa to see if that fixes it.

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how to calculate screen to world point (custom) 0 Answers

full screen wide GUI.Box 3 Answers

know GUILayout current screen position 2 Answers

Interface 3D 1 Answer

GUI button in middle of screen 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