Skip to content

Instantly share code, notes, and snippets.

@jmschrack
Created January 23, 2017 06:09
Show Gist options
  • Save jmschrack/2f93e298ad8268a96afb8130fc5796e2 to your computer and use it in GitHub Desktop.
Save jmschrack/2f93e298ad8268a96afb8130fc5796e2 to your computer and use it in GitHub Desktop.
For Unity3D, converts Trigger methods into Delegates.
using UnityEngine;
using System.Collections;
public class TriggerCallback : MonoBehaviour {
public delegate void Enter(Collider other);
public Enter enter;
public delegate void Exit(Collider other);
public Exit exit;
public delegate void Stay(Collider other);
public Stay stay;
void Awake(){
enter+=DoNothing;
exit+=DoNothing;
stay+=DoNothing;
}
void DoNothing(Collider other){}
void OnTriggerEnter(Collider other){
enter(other);
}
void OnTriggerExit(Collider other){
exit(other);
}
void OnTriggerStay(Collider other){
stay(other);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment