I want to do a game where the map is cell based, like Pokemon, where when you press Left, you move from 210x100 to 209x100.
Like this:
void Update()
{
var x = Input.GetAxis("Horizontal");
var z = Input.GetAxis("Vertical");
if (x == 0 && z == 0)
{
return;
}
if (x > 0)
{
x = 1;
} else if (x < 0)
{
x = -1;
}
if (z > 0)
{
z = 1;
} else if (z < 0)
{
z = -1;
}
transform.Translate(
x,
0f,
z,
Space.World
);
}
But with this approach, when you quick press and release the left, the Update is executed many times and you go from 210 to 203 easily.
How can I move from 210 to 209 in 0,5 seconds and don't allow other movement until the current movement has finished?