Boolean does not set back to true

Hi guys,

I have a boolean variable in my game that I use to control how many times a NPC can move each turn. It’s a tactical RPG. The NPC can move just once per turn. The boolean is called canMoveNPC and it’s initialized as true. Then, when the NPC reaches his destination, I set it to false.

However, when I pass the turn to the human player, I want this variable to be true again, because in this way, the NPC is able to move again when it’s his turn. But it doesn’t set back to true, it stays as false. I don’t know what I’m doing wrong.

This code I use to move the NPC and set the variable to false:

public void Move()
    {
        for (int i = 0; i < mov.NPCS.Length; i++)
        {
            if (!Physics.Raycast(Sherrif.transform.position, Sherrif.Left_Right, out Sherrif.hitRight) || Sherrif.hitLeft.transform.tag != "Human")
            {
                if (mov.gameManager.NPCTurn && canMoveNPC )
                {
                    mov.NPCPlayer = mov.NPCS[2];
                    mov.NPCS[2].GetComponent<NPC>().isNPC = true;
                    IsMoving = true;

                    this.transform.position = Vector3.MoveTowards(this.transform.position, targetPosition, velocity * Time.deltaTime);
                }

                if(this.transform.position == targetPosition)
                {
                    mov.NPCS[2].GetComponent<NPC>().isNPC = false;
                    IsMoving = false;
                    canMoveNPC = false;
                }
            }
        }
    }

And here, I have a game manager that I use to control the turns and set the variable to true again. I use the code bellow when the NPC passes his turn:

else if (mov.gameManager.playerTurn == 2)
        {
            mov.gameManager.playerTurn = 1;
            mov.gameManager.NPCTurn = false;
            mov.gameManager.HumanTurn = true;
            mov.TurnEnd();
            mov.interfaceManager.ChangeTurn();

            for (int i = 0; i < mov.NPCS.Length; i++)
            {
                mov.NPCS*.GetComponent<NPC>().canMoveNPC = true;*

}
}
How could I solve it?

Check the value of targetPosition when the new turn is executing.
Maybe you have to update targetPositionso it’s different than this.transform.position anymore before the turn of your NPC.
You could probably have a method called on the current NPC such as StartTurn() where you reset your turn related parameters before calculating the move.

The only possible way it wouldn’t be getting set to true is that else if isn’t getting called, whether the playerTurn != 2 or a previous if statement runs, could I see the whole method that this code is in?