简体   繁体   中英

Unity/C# wait until bool becomes true

This line of code waits until bool becomes true. yield return LocalizationSettings.InitializationOperation;

I need to do similar thing. I have a bool variable in script A, script B has to check and shouldn't be running until Script's A bool becomes true.

A simple solution could be to add an if(check) at the start of Update (or FixedUpdate) of class B

//on class B
private A classA;

void Update(){
  if(!classA.valueToCheck) return;
  //do your stuff
}

As you mentioned, there is more in deep solution with yield and coroutine. If the simple solution isn't enough for your need, you should start by looking at Unity documentation, and learn how to use and implement coroutine: https://docs.unity3d.com/Manual/Coroutines.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM