- Home /
bool changing on its own?
I'm making a game where I want the player to turn when it gets too far to the side. To do this I created a coroutine named "nearWalls" which controls the turning. I'm using the bool "nearWall" to prevent the coroutine from constantly being run over and over again since I only want it to be run once. However, when the if statement is satisfied, the bool keeps changing from true to false. I'm really confused as to why the bool keeps changing since to me it looks like it should only ever change once after the application runs, which is when the if statement is satisfied. Any help would be appreciated, thanks!
public class Froggy : MonoBehaviour {
bool nearWall = false;
void Update () {
Debug.Log ("the nearWall bool is: " + nearWall);
if (transform.position.x >= 13f || transform.position.x <= -13f) {
if (nearWall == false) {
nearWall = true;
StartCoroutine (nearWalls ());
}
}
IEnumerator nearWalls(){
//nothing changing the nearWall bool
}
}
Before if statement is satisfied:
After if statement is satisfied:
Your answer
Follow this Question
Related Questions
Get the number of false bools in GameObject[] (array) 3 Answers
Render object with different shader depending on the camera 2 Answers
Manipulating the location of the VR controllers (Vive/SteamVR) in script 0 Answers
Unity 5: How to display bird eye view layout of a 3D scene with UI component overlay on screen? 1 Answer
Set a Bool Through Function 1 Answer