How to DELAY A FUNCTION in UNITY - INVOKE and COROUTINES

Опубликовано: 06 Октябрь 2024
на канале: GDT Solutions
442
8

In this video we see how to use the Invoke function and Coroutines to add delay to functions in Unity.

The Invoke method can be used in any script that inherits from MonoBehaviour (basically all scripts that we create in Unity, unless we explicitly remove the inheritance), to use Invoke you need two parameters, the first parameter is a string with the exact name of the function you want to call, the second parameter is a float with the amount of seconds after which the function will be called.

A coroutine on the other hand, is like a function you need to define, a function that returns an "IEnumerator" type object. Coroutines can be interrupted and resumed by us, using the "yield" keyword.

____________________________________________________________
PORTFOLIO: https://gamedevtraum.com/en/portfolio...
CONTACT:   / gamedevtraum  
LINKEDIN:   / gamedevtraum  
____________________________________________________________