0
0
Unityframework~10 mins

Why coroutines handle time-based logic in Unity - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start a coroutine that waits for 2 seconds.

Unity
StartCoroutine([1]());

IEnumerator WaitAndPrint() {
    yield return new WaitForSeconds(2);
    Debug.Log("Waited 2 seconds");
}
Drag options to blanks, or click blank then click option'
AStart
BWaitForSeconds
CWaitAndPrint
DPrintAfterWait
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the wrong method name that does not return IEnumerator.
Forgetting to use StartCoroutine to run the coroutine.
2fill in blank
medium

Complete the code to pause execution inside a coroutine for 3 seconds.

Unity
IEnumerator PauseCoroutine() {
    yield return new [1](3);
    Debug.Log("Paused for 3 seconds");
}
Drag options to blanks, or click blank then click option'
AWaitUntil
BWaitForEndOfFrame
CWaitForFixedUpdate
DWaitForSeconds
Attempts:
3 left
💡 Hint
Common Mistakes
Using WaitForEndOfFrame which waits only until the frame ends.
Using WaitUntil without a condition.
3fill in blank
hard

Fix the error in the coroutine that should wait 1 second before printing.

Unity
IEnumerator PrintAfterDelay() {
    yield return new [1](1);
    Debug.Log("Printed after 1 second");
}
Drag options to blanks, or click blank then click option'
AWaitSeconds
BWaitForSeconds
CWaitSecond
DWaitForSecond
Attempts:
3 left
💡 Hint
Common Mistakes
Misspelling the class name causes compile errors.
Using a non-existent class like WaitSeconds.
4fill in blank
hard

Fill both blanks to create a coroutine that waits 5 seconds and then prints a message.

Unity
IEnumerator DelayedMessage() {
    yield return new [1](5);
    Debug.Log([2]);
}
Drag options to blanks, or click blank then click option'
AWaitForSeconds
B"Hello after delay"
C"Message sent"
DWaitForEndOfFrame
Attempts:
3 left
💡 Hint
Common Mistakes
Using WaitForEndOfFrame instead of WaitForSeconds for time delay.
Forgetting to put quotes around the message string.
5fill in blank
hard

Fill all three blanks to create a coroutine that waits 2 seconds, then waits until a condition is true, and finally prints a message.

Unity
IEnumerator WaitForCondition() {
    yield return new [1](2);
    yield return new [2](() => [3]);
    Debug.Log("Condition met!");
}
Drag options to blanks, or click blank then click option'
AWaitForSeconds
BWaitForEndOfFrame
CisReady
DWaitUntil
Attempts:
3 left
💡 Hint
Common Mistakes
Using WaitForEndOfFrame instead of WaitUntil for condition wait.
Passing a variable name without a lambda function to WaitUntil.