Join Kelley Hecker for an in-depth discussion in this video Using Coroutine and InvokeRepeating, part of Scripting Unity with C#.
- While you can use update to do something every frame…in some cases you might only want to run…some code every few seconds, or stop code…from executing when a certain condition is met.…You also might have code that needs to run…over multiple frames rather than…completing everything in a single update.…Two alternatives to using update,…are Coroutines and InvokeRepeating.…InvokeRepeating calls a function repeatedly…at a certain interval.…Imagine you have a cannon that should…fire a shot every five seconds.…If you were using update,…you would have to keep track of a timer…and check the timer each frame…to see if you've reached five seconds.…
With InvokeRepeating, you just have to call…InvokeRepeating with your function name FireCannon…and repeat rate five seconds,…and then the function will automatically…be called every five seconds.…You can also delay the first call to the function,…by using the second parameter.…If you don't want a delay, use a small number like .001…instead of zero.…There's a bug where InvokeRepeating…
- 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?
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.