rabidus-test/Assets/Scripts/SimpleTrigger.cs

39 lines
983 B
C#
Raw Permalink Normal View History

2023-07-24 16:38:13 +03:00
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);
}
}
}