39 lines
983 B
C#
39 lines
983 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
public class SimpleTrigger : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private LayerMask _layerMask;
|
|
|
|
public UnityEvent<Collider> OnTriggerEnterEvent;
|
|
public UnityEvent<Collider> OnTriggerStayEvent;
|
|
public UnityEvent<Collider> OnTriggerExitEvent;
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if ((_layerMask.value & (1 << other.transform.gameObject.layer)) > 0)
|
|
{
|
|
OnTriggerEnterEvent?.Invoke(other);
|
|
}
|
|
}
|
|
|
|
private void OnTriggerStay(Collider other)
|
|
{
|
|
if ((_layerMask.value & (1 << other.transform.gameObject.layer)) > 0)
|
|
{
|
|
OnTriggerStayEvent?.Invoke(other);
|
|
}
|
|
}
|
|
|
|
private void OnTriggerExit(Collider other)
|
|
{
|
|
if ((_layerMask.value & (1 << other.transform.gameObject.layer)) > 0)
|
|
{
|
|
OnTriggerExitEvent?.Invoke(other);
|
|
}
|
|
}
|
|
}
|