• 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 _gord0_ · May 06, 2017 at 03:31 PM · androidpositionmobiletouch

Moving a GUI Image to the same position as a touch

Hello everyone. My current game will be on windows, linux, osx, android, and ios. I'm currently using a "fake" mouse cursor. Meaning the system mouse is hidden and locked to center. I needed to do this for other functionalities to work. Anyway, works great on the desktop operating systems. On Android what I'm doing to save extra coding was simply moving the fake mouse cursor to the touch position (on touch begin and only when there's only 1 finger touching). That way the rays that fire from the fake mouse cursor will work the same way. Yes I'm using selective compilation (#if UNITY_ANDROID || UNITY_IOS).

 #if UNITY_ANDROID || UNITY_IOS
 if (Input.touchCount>0 && Input.touchCount<2)
 {
     Touch t=Input.GetTouch(0);
     if (t.phase==TouchPhase.Began) {CursorRT.position=t.position;}
 }
 #endif


CursorRT is the RectTransform of the fake mouse. Right after this code is the regular ray casting stuff that determines what the click/touch does which is working fine. Right now there seems to be an offset. The center point of the fake cursor Image is in the center of the image, not one of the corners, so I'm not sure what's causing it. I find the cursor shows up about 2cm away from my touch point when running on my phone. I can make it work by taking the offset into account and then touching the wrong place to make the cursor goto the right place so I know most of the code is working properly, the only problem being this offset. If i can sort that out, I can make the cursor invisible on mobile and carry on with the rest of the game.

Any help in figuring out why there's an offset would be much appreciated.

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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

153 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 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 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 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

OnPointerExit Issue w/ Radial Menu on Android 1 Answer

How can I get the current x position of touch in Android? 2 Answers

mobile programming questions 1 Answer

Box Drag and throw away script for mobile? 0 Answers

Mobile FPC in unity 5 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges