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
0
Question by Jonesy19 · Jul 10, 2014 at 03:43 PM · touchscreenipadscreentoworldpoint

iPad touch is offset! Unity2d.

Hi Everyone, My game was working fine until I upgraded to Unity 4.5.1. I have code that simply detects if an object is touched.
It works in the Unity Game window, it works on Android, but for some reason, the x value on the iPad is offset by 10 (after screentoworldpoint is run).

Is there a reason why upgrading Unity would change this? Was I doing it wrong to begin with? Either way, does anyone have any ideas on how to fix this?

Thanks, -Will

 public int hasTouchedObject(GameObject objectToCheck)
     {
         //Debug.Log ("Camera Location: x: " + GameObject.Find("Main Camera").transform.position.x + ": y: " + GameObject.Find("Main Camera").transform.position.x + ": z: " + GameObject.Find("Main Camera").transform.position.z);
         setTouches();
         for (int x = 0; x < touchList.Count; x++)
         {
             Touch thisTouch = touchList[x];
             //string touchphase = thisTouch.phase.ToString();
             if (thisTouch.phase == TouchPhase.Began) 
             {
                 Debug.Log ("touch x: " + thisTouch.position.x + " touch y: " + thisTouch.position.x);
                 Vector3 wp = Camera.main.ScreenToWorldPoint(new Vector2(thisTouch.position.x, thisTouch.position.y));
                 Debug.Log ("Cam x: " + Camera.main.transform.position.x + " Cam y: " + Camera.main.transform.position.x + " Cam z: " + Camera.main.transform.position.z);
                 Vector2 touchPos = new Vector2(wp.x, wp.y);
 
                 Collider2D[] allpoints = Physics2D.OverlapPointAll(touchPos);
                 Debug.Log ("Touch point x: " +  touchPos.x + " ::: Touch point y: " + touchPos.y);
                 for (int y = 0; y < allpoints.Length; y++)
                 {
                     //Debug.Log ("All Touch Point" + y);
                     if (objectToCheck.collider2D == allpoints[y])
                     {
                         Debug.Log ("FOUND!!!");
                         return y;
                     }
                 }
             }
         }
         return -1;
     }

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
0
Best Answer

Answer by Jonesy19 · Jul 10, 2014 at 05:40 PM

In case anyone else is running into the same issue, I figured out the problem. For whatever reason, when I was using the code "Screen.Orientation = Landscape.Left", that was throwing off the ScreenToWorldPoint coordinates into thinking it was portrait...Anyways, I removed ALL instances in my code where I was manually changing the screen orientation and allowed Unity to do it by default in the Player Settings inspector, and now it's working fine.

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 kboudai · Sep 15, 2014 at 11:17 PM

I got the same bug. You just need to update Unity >= 4.5.3.

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

2 People are following this question.

avatar image avatar image

Related Questions

Viewport to World Coordinates 2 Answers

Novice problem on Android with Touch position and object world placement. Help! 3 Answers

Problem with ScreenToWorldPoint and touches (C#) 2 Answers

How to set screen boundaries? 1 Answer

I try to Create a DLL for get WM_TOUCH windows message! 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