Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 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 /
  • Help Room /
avatar image
2
Question by Lazybones94 · Oct 13, 2015 at 11:53 AM · uicoordinatesrecttransform

Convert Screen point to UI rectangle coordinates

Hello everybody! I know there's a similiar questioin here, but I have problems with it. I need to conver the Input.mousePosition into the coordinates within the UI Image for further convertation into texture pixels and using GetPixel() onto the texture of this UI Image. But the problem is converting Input.mousePosition into UI coordinates. I try RectTransformUtility.ScreenPointToLocalPointInRectangle(myRect, Input.mousePosition, null, out tmpVec), but it ALWAYS returns true, no matter where mouse is, over the image or not, and the out Vector2 parameter has the position of the mouse relative to the center of the image(why?), and I just think it works not the way it is described in documentation. The RectTransformUtility.RectangleContainsScreenPoint(myRect, Input.mousePosition) works as described - it REALLY returns true when mouse is over the image, and false when it is not. But it gives out no coordinates that can be converted to use the GetPixel func. Please anyone help?

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

2 Replies

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

Answer by Lazybones94 · Oct 13, 2015 at 08:12 AM

I solved this problem by myself. The problem was that the UI rect coordinates are positioned to the pivot point of the UI element, and it confused me a lot, because the pivot of myRect is in the center of the image. So I needed just to calculate the out tmpVecinto the understandable coordinates for further usage like this:

             if(tmpVec.x < 0)
             {
                 coordX = colorPalette.rect.max.x + tmpVec.x;
             }
             else if(tmpVec.x >= 0)
             {
                 coordX = tmpVec.x + colorPalette.rect.max.x;
             }
 
             
             if (tmpVec.x < 0)
             {
                 coordY = colorPalette.rect.max.y + tmpVec.y;
             }
             else if (tmpVec.x >= 0)
             {
                 coordY = tmpVec.y + colorPalette.rect.max.y;
             }
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 fermmmm · May 12, 2016 at 02:58 AM

I did a coordinate translation tool for the UI to convert from / to: Screen Space (pixels), anchor coordiantes, rect coordinates, canvas coordinates, coordinates of objects located at different containers, etc. Take a look: http://forum.unity3d.com/threads/released-ui-rect-transform-extended.403626/

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

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

39 People are following this question.

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

Related Questions

RectTransform offset renders wrong (UnityAndroid) 0 Answers

Help! with the Message text 0 Answers

Layout Group failes to resize children automatically and can't force resize by script when adding child 1 Answer

How to offset a RectTransform? 0 Answers

UI Canvas Anchor points are stuck in the bottom left corner and disabled when in overlay mode. 1 Answer


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