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?