Having struggled with touch input in games and testing games on an android device i have been using using unity remote 4 on a Nexus 7 2012 (1st Gen) and to master touch input i have been using
if (Input.touchCount > 0)
on a UI Button which seems to solve my problem as whenever i touch the screen Input.touchCount
equals 1 and that works, my code is below;
public class Left : MonoBehaviour {
GameObject car;
int speed = 100;
// Use this for initialization
void Start ()
{
car = GameObject.Find("Car");
}
// Update is called once per frame
void Update()
{
if (Input.touchCount > 0)
{
car.transform.Rotate(Vector3.up * Time.deltaTime * speed);
Debug.Log("LEFT");
}
}
}
It is very simple code which is easy for me than confusing event managers or other ways to do touch input. But the problem is when I release touch on the button which this code is attached to, both the car rotation and debug logging of “LEFT” continues for a short period, at least one second which could be catastrophic for me when i create simple games focused on reaction.
Thank you for reading my question, I would hope their is a solution to avoid the lag or I can blame it on my old device and unity remote, meaning it would work if i actually released it. Opinions or answers would be much thanked!