Making sure playermodel only moves 1 unit

I am doing a school assignment based off of the Unity3D tutorial 2D RogueLike (all code available here)

In my version though, the movement is not turnbased and I am having some trouble figuring it out.

If I I make the player lose its turn after movement, the character will stay perfectly aligned with the grid. But if I let the player keep his turn, the character moves in increments not in alignment with anything(ór how long the computer think I held down the movebutton for).

I tried to fix it with this:

	GameManager.instance.playersTurn = false;

	Thread.Sleep(500);

	GameManager.instance.playersTurn = true;

and it sort of ‘fixes’ it. It now only moves 1 unit, provided I don’t hold down the movebutton for longer than the 500ms, hereafter it seems to ‘lose sync’ with the board again… Also, it now takes 500ms from i press move, till the character actually moves.

Here is an example of how it looks if i just quickly tap the button to move(so its in sync)
47728-insyncexample.png

and here is one when i held down the button for more than the 500ms ( out of sync)
47729-outofsyncexample.png

So the specific question.

How do I make sure that the character only moves 1 tile/unit with a single button press?

I would greatly appreciate a solution to this

Thread.Sleep will pause the execution of everything, so it’s not a very good idea.

What you want is for your script to know which square it’s supposed to go to, and then move towards that if you’re not there yet.

So if your player character is at 5/5, and the player presses “right”, you don’t want to try to move the player character 1 to the right, you want to move it towards 6/5. Something like:

int myXCoordinate;
int myYCoordinate;

void Update() {
    if(Input.GetKeyDown(KeyCode.Right)) {
        myXCoordinate++;
    }

    ...

    Vector2 wantedPosition = new Vector2(myXCoordinate, myYCoordinate);
    transform.position = Vector2.MoveTowards(transform.position, wantedPosition, Time.deltaTime * moveSpeed);
}

You’ll have to handle stuff like being out of bounds or whatever, but that should be enough to get you started.