Invoke method after time gap easy way Unity 3d | Invoke and coroutines in unity

Subscribers:
1,110
Published on ● Video Link: https://www.youtube.com/watch?v=IdUxqV53fGQ



Duration: 2:21
22 views
2


In this video I have shown a little description of how we can invoke anything like a method after time gap using

* Invoke method
* Coroutine and IEnumerator

Code :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/////////// thank you ////////////
public class TimegapExample : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
//Invoke (nameof(WaitThenprint),2.0f);

//or Invoke(WaitThenprint,2.0f);

////////////// for passing parameters we use coroutine and ienumerators ////////////////
StartCoroutine(WaitThenPrint(2.0f,"ht"));

}

///////////// this method simply prints "k"
void WaitThenprint(){
print("k");
}

////////////// this will print the passed string after time gap which is also specified in parameter/////////
IEnumerator WaitThenPrint(float timegap,string message){
yield return new WaitForSeconds(timegap);
print(message);
}

}







Tags:
Invoke after time gap
time gap
coroutine in unity
unity
unity3d
IEnumeratr in unity
leran unity3d