Join Kelley Hecker for an in-depth discussion in this video Using Update instead of Coroutine, part of Scripting Unity with C#.
- Like I mentioned in an earlier video,…you could create the spinning, floating coin…using Update instead of Coroutines.…I'll now show you how to modify the coin script…to use Update.…Remember to input the additional assets…from the Asset Store if you haven't already…as I showed you earlier in this chapter.…Open the coin script.…The first thing we can do…is remove the StartCoroutine calls…from the start function…and change the return type of the Spin and Float functions…to be void instead of IEnumerator.…
We also need to remove the yield functions…because those can only be called…within a function that returns IEnumerator.…Now Spin and Float are just ordinary functions.…Most of the code inside Spin and Float can stay the same.…Our code was designed to run every frame,…gradually moving the coin over time,…which is what we want for a function…that's going to be called from Update…but we do need to remove the while loop.…
Before, we were using the while loop…to make our code execute every frame…but now, Update will do that for us.…
- Defining classes and variables
- Attaching scripts to objects
- Understanding MonoBehaviour class
- Using the Unity Scripting API
- Importing assets
- Using a singleton pattern to manage game state
- Creating an event
Skill Level Intermediate
Advanced Unity 3D Game Programmingwith Michael House3h 45m Advanced
Creating Mobile Games with Unitywith Kelley Hecker1h 12m Intermediate
1. Your First Script
3. Built-In Unity Classes
Picking up coins4m 8s
5. Events and Delegates
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.