If a variable used by a coroutine is changed, will the coroutine know while it is running?
I have a coroutine that drops seeds on ScriptA. Once it drops a seed to a position it changes the "position open" bool on ScriptA to false. When the player picks up the seed its script, ScriptB, updates the bool of ScriptA. However, the coroutine on Script A is always running so I am wondering if it knows the bool has been updated. I'm wondering because it doesn't work...
Answer by Dave-Carlile · Oct 13, 2015 at 12:27 PM
I usually keep an empty scene in my project so I can go test things out when I'm not completely sure how they work. It can be valuable to strip everything away except for the specific thing you're trying to test. This helps separate bugs in your logic from misunderstandings about how something works.
bool testValue;
IEnumerator TestCoroutine()
{
Debug.Log("Test Value: " + testValue);
yield return WaitForSeconds(1.0f);
}
void Start()
{
StartCoroutine(TestCoroutine());
}
void Update()
{
testValue = Input.GetKeyDown(KeyCode.Space);
}
}
Your answer
Follow this Question
Related Questions
Coroutine not working on android build 1 Answer
How to wait for a function to complete before continuing? 0 Answers
Detect when a key is pressed or not pressed using Corutine? 0 Answers
What happens when calling StopCoroutine on a Coroutine that is awaited somewhere else ? 0 Answers
How to properly call Async Task 0 Answers