I’m creating a movement script where the player must tap either the left or right side of the screen. Currently my script is working however I can simply hold my finger on the screen to move continuously in the respective direction. It shouldn’t be allowed to happen. How can I change it so that it only registers a tap and not a touch/hold?
void Update()
{
if (Input.touchCount > 0)
{
var touch = Input.GetTouch(0);
float jumpVelocity = 3f;
if (touch.position.x < Screen.width / 2)
{
rigidbody2d.velocity = (Vector2.up * jumpVelocity) + (Vector2.left * jumpVelocity);
}
else if (touch.position.x > Screen.width / 2)
{
rigidbody2d.velocity = (Vector2.up * jumpVelocity) + (Vector2.right * jumpVelocity);
}
}
}