I want to move objects exactly in one unit. When the user touches the right side it moves 01 unit on right and when pressing the left side it should move one unit left. I tried the below script but was unable to achieve my goal. If anyone knows about it kindly guide me.
void Update()
{
touchPosition = Camera.main.ScreenToWorldPoint(touch.position);
if (Input.GetButtonDown("Jump") || Input.GetMouseButtonDown(0))
{
if (touchPosition.x > 0)
{
transform.Translate(1f, 0, 0);
}
else if (touchPosition.x < 0)
{
transform.Translate(-1f, 0, 0);
}
}
}