So i’m just starting to learn touch controls in unity. I want to move an object in world space to the position on screen where i touched it. This is my code used from Brackey’s tutorial. But it only works once per play session. Any idea why?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TouchToMove : MonoBehaviour {
// Update is called once per frame
void Update ()
{
if(Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
Vector3 touchPosition = Camera.main.ScreenToWorldPoint(touch.position);
touchPosition.z = 0f;
transform.position = touchPosition;
}
}
}