Recall & Review
beginner
What is a coroutine in Unity?
A coroutine is a special function that can pause its execution and resume later, allowing Unity to handle tasks over multiple frames without freezing the game.
Click to reveal answer
beginner
Why are coroutines useful for time-based logic?
Coroutines let you wait for a certain time or event without stopping the whole game, making it easy to run actions after delays or over time.Click to reveal answer
intermediate
How does a coroutine pause and resume in Unity?
It uses the 'yield' keyword to pause at a point, then Unity resumes it after the specified wait time or condition is met.
Click to reveal answer
beginner
What happens if you use a normal function for time delays instead of a coroutine?
The game would freeze or stop responding because normal functions run all at once and can't pause without blocking the game loop.
Click to reveal answer
beginner
Give a simple example of a coroutine handling a 3-second wait.
Example: <br>
IEnumerator WaitThreeSeconds() {<br> yield return new WaitForSeconds(3);<br> Debug.Log("3 seconds passed");<br>}Click to reveal answer
What keyword does Unity use to pause a coroutine?
✗ Incorrect
The 'yield' keyword pauses the coroutine until the next frame or a specified wait time.
Why can't normal functions handle time delays without freezing the game?
✗ Incorrect
Normal functions execute completely before returning, so they can't pause and cause the game to freeze during delays.
Which Unity class is commonly used inside coroutines to wait for seconds?
✗ Incorrect
WaitForSeconds tells the coroutine how long to pause before continuing.
What is the main benefit of using coroutines for animations or timed events?
✗ Incorrect
Coroutines let you run code over time smoothly without stopping the game.
How do you start a coroutine in Unity?
✗ Incorrect
StartCoroutine is the Unity method used to begin running a coroutine.
Explain in your own words why coroutines are ideal for handling time-based logic in Unity.
Think about how games keep running smoothly while waiting.
You got /4 concepts.
Describe how you would use a coroutine to make an action happen after a 5-second delay.
Remember the steps to pause and resume execution.
You got /3 concepts.