Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
2
Question by DaveA · Jun 23, 2011 at 12:35 AM · inputpositiontouchscreen

Input Touch.position 'inverted' relative to screen?

Sorry if this has been covered elsewhere, I did not see it.

Is the Input's Touch position 'inverted' relative to the screen? The reason I ask is that if I do this:

 var touch = Input.GetTouch(0);
 if (windowRect.Contains(touch0.position))
 {
   .. do something ..
 }

where windowRect is set in OnGUI:

 windowRect = GUILayout.Window(GetInstanceID(), windowRect, DisplayData, "title");

It will only 'do something' IFF I touch the screen in the 'mirrored' position (up/down aka Y direction). Ex: if my windows is near the top of my screen, it will not detect this containment if I touch near the top (inside the window). But it WILL detect if I touch on the opposite side of the screen (same X, opposite Y).

I must have missed something in the docs? Or is it a bug?

Update: Is this what GUIUtility.ScreenToGUIPoint is for?

Comment
Add comment · Show 2
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 ina2 · Mar 27, 2012 at 05:55 AM 0
Share

Yoda, I can't believe you've been stumped by this same invertedness !

avatar image DaveA · Mar 28, 2012 at 02:41 AM 0
Share

We were all new once....

1 Reply

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

Answer by Dreamblur · Jun 23, 2011 at 12:41 AM

Technically, it is not inverted. Touch position and mouse position are returned by the Input class in screenspace coordinates, whereas OnGUI uses GUI space coordinates. In screenspace, (0, 0) is on the bottom-left corner of the screen while it is on the top-left corner of the screen in GUI space.

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 DaveA · Jun 23, 2011 at 12:46 AM 1
Share

$$anonymous$$y puzzlement is that this same check for $$anonymous$$ouse coordinates seems to be ok. At least, I haven't noticed any problems. But Touch coordinates seem backward. I tried copying the windowRect and setting y to Screen.height-windowRect.y, but that didn't help. I'm not sure if these GUIUtility funcs will help, nor which one (ScreenToGUI or GUIToScreen) would be better. Trying them now...

avatar image Dreamblur · Jun 23, 2011 at 12:59 AM 0
Share

To convert screenspace coordinates to GUI space coordinates:

  new Vector2(screenspace.x, Screen.height - screenspace.y) // where screenspace is the Vector2 in screenspace coordinates
avatar image DaveA · Jun 23, 2011 at 01:03 AM 0
Share

Yep, that's pretty much I just came up with too. Thanks. I think the difference is (and btw the GUIUtility funcs didn't work) because I was doing this in Update and not OnGUI.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Touch.position, Touch.deltaPosition, Screen.width, Screen.Height 1 Answer

Input.GetTouch(0) doesn't work 2 Answers

Exporting to Touch Screen Monitors or Touch Screen Displays 0 Answers

unity 5.2 Input.GetTouch(0).position incorrect? 3 Answers

Get touch position? 0 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