Skip to content

Instantly share code, notes, and snippets.

@jmschrack
Last active January 23, 2017 07:21
Show Gist options
  • Save jmschrack/ad165ecd350b4c0eaf20e56b6464900a to your computer and use it in GitHub Desktop.
Save jmschrack/ad165ecd350b4c0eaf20e56b6464900a to your computer and use it in GitHub Desktop.
For Unity3D Triggers, lets you attach UnityEvents to Trigger events
using UnityEngine;
using UnityEngine.Events;
using System.Collections;
public class TriggerEvent : MonoBehaviour {
public bool EnterOnce;
bool enterFire;
public UnityEvent EnterEvent;
public bool StayOnce;
bool stayFire;
public UnityEvent StayEvent;
public bool ExitOnce;
bool exitFire;
public UnityEvent ExitEvent;
void OnTriggerEnter(Collider other){
if(!EnterOnce||(EnterOnce&&!enterFire)){
EnterEvent.Invoke();
}
}
void OnTriggerStay(Collider other){
if(!StayOnce||(StayOnce&&!stayFire)){
StayEvent.Invoke();
}
}
void OnTriggerExit(Collider other){
if(!ExitOnce||(ExitOnce&&!exitFire)){
ExitEvent.Invoke();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment