Question by
SteadyCraft · Aug 31, 2017 at 07:06 PM ·
camera2dtouchcoordinate-system
Move a GameObject to touch position
I'm making a simple game where the player body follows the touch. If I tap anywhere on the screen, it should instantly snap to the position. When I drag my finger across the screen, it should keep following without lag.
private void Update()
{
if (Input.touchCount > 0)
{
Touch myTouch = Input.touches[0];
if (myTouch.phase == TouchPhase.Began)
{
Vector2 Touchpos = c.ScreenToWorldPoint(new Vector2(myTouch.position.x, myTouch.position.y));
rb2d.transform.position = Touchpos;
}
}
}
However, it doesn't work. I tried displaying the myTouch coordinates on-screen via text, but it didn't show anything either. What am I doing wrong?
Comment