Created
November 5, 2024 23:37
-
-
Save andydbc/f5b092f40c52532184910caff8e37610 to your computer and use it in GitHub Desktop.
A lightweight helper to forward trigger events from a GameObject to listeners.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.Events; | |
public class TriggerEventDispatcher : MonoBehaviour | |
{ | |
public delegate void OnTriggerEnterEvent(Collider other); | |
public event OnTriggerEnterEvent TriggerEnter; | |
public delegate void OnTriggerExitEvent(Collider other); | |
public event OnTriggerEnterEvent TriggerExit; | |
void OnTriggerEnter(Collider col) | |
{ | |
TriggerEnter?.Invoke(col); | |
} | |
void OnTriggerExit(Collider col) | |
{ | |
TriggerExit?.Invoke(col); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment