rabidus-test/Assets/Scripts/SplineTrigger.cs

47 lines
1.1 KiB
C#

using Dreamteck.Splines;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class SplineTrigger : MonoBehaviour
{
[SerializeField]
private LayerMask _layerMask;
[SerializeField]
private bool _triggerOnce = true;
private bool _triggered = false;
public UnityEvent<Collider> OnTriggerEvent;
public UnityEvent<Collider> OnTriggerStayEvent;
private void OnTriggerEnter(Collider other)
{
if (_triggerOnce && _triggered)
return;
if ((_layerMask.value & (1 << other.transform.gameObject.layer)) > 0)
{
if (_triggerOnce)
_triggered = true;
OnTriggerEvent?.Invoke(other);
}
}
private void OnTriggerStay(Collider other)
{
if (_triggerOnce && _triggered)
return;
if ((_layerMask.value & (1 << other.transform.gameObject.layer)) > 0)
{
if (_triggerOnce)
_triggered = true;
OnTriggerStayEvent?.Invoke(other);
}
}
}