Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to wait for 2 seconds before printing a message.
Unity
IEnumerator WaitAndPrint() {
yield return new [1](2f);
Debug.Log("Waited 2 seconds");
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using WaitForEndOfFrame instead of WaitForSeconds.
✗ Incorrect
WaitForSeconds pauses the coroutine for the given seconds.
2fill in blank
mediumComplete the code to wait until the end of the current frame before continuing.
Unity
IEnumerator WaitForFrameEnd() {
yield return new [1]();
Debug.Log("Frame ended");
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using WaitForSeconds with no time parameter.
✗ Incorrect
WaitForEndOfFrame waits until the frame rendering is done before continuing.
3fill in blank
hardFix the error in the coroutine to wait for 3 seconds before printing.
Unity
IEnumerator WaitThreeSeconds() {
yield return new [1](3f);
Debug.Log("3 seconds passed");
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using WaitForEndOfFrame which takes no parameters.
✗ Incorrect
WaitForSeconds requires a float parameter for seconds to wait.
4fill in blank
hardFill both blanks to create a coroutine that waits for the end of frame, then waits 1 second.
Unity
IEnumerator WaitFrameThenSecond() {
yield return new [1]();
yield return new [2](1f);
Debug.Log("Waited frame end and 1 second");
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of waits or using wrong classes.
✗ Incorrect
First wait for the frame to end, then wait for 1 second.
5fill in blank
hardFill all three blanks to create a coroutine that waits 0.5 seconds, then waits for frame end, then waits 2 seconds.
Unity
IEnumerator ComplexWait() {
yield return new [1](0.5f);
yield return new [2]();
yield return new [3](2f);
Debug.Log("Completed complex wait");
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using WaitForFixedUpdate or WaitUntil incorrectly.
✗ Incorrect
Wait 0.5 seconds, then wait for frame end, then wait 2 seconds.