- Home /
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.
Your answer
Follow this Question
Related Questions
Touch stopped working, works in remote 2 Answers
Raycast from player to touch point? 2 Answers
Create on Gui controls for Mobile Devices (Android) 1 Answer
Different animations on mobile 0 Answers
Lean touch - Move object in X and Z axis 0 Answers