I’m developing and AI and I’m wanting to delay the decision making process, so I’m using a coroutine. It’s meant to check the distance of the Player, and edit an int to determine if it should move or not. The coroutine is supposed to edit a variable named “MoveZ” but whenever I check the value after the coroutine runs, it doesn’t change the value. Here’s my code:
Declaring the method
IEnumerator FindRun(int Z){
if (Distance > 3){
Z = 1;
}
else if (Distance < 2){
Z = -1;
}
else{
Travelling = false;
}
yield return new WaitForSeconds(.1f);
} // Closes FindRun
In Update
StartCoroutine ("FindRun", MoveZ);
What am I doing wrong? I’m not sure what “return” does, does it have anything to do with that?