Skip to content

Instantly share code, notes, and snippets.

@ihsanberahim
Last active August 29, 2015 14:05
Show Gist options
  • Save ihsanberahim/baea2d57d8cbdf1cb6ca to your computer and use it in GitHub Desktop.
Save ihsanberahim/baea2d57d8cbdf1cb6ca to your computer and use it in GitHub Desktop.
How to use delegate and event in Unity
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class GameSystem : MonoBehaviour
{
public delegate void Route();
public static event Route OnPlay;
void Start ()
{
OnPlay += defaultOnPlay;
StartCoroute(delayStart());
}
//Helper
IEnumerator delayStart()
{
return yield new WaitForSeconds(3);
OnPlay();
Debug.Log("Game Started....");
}
void defaultOnPlay()
{
//do something
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment