rabidus-test/Assets/Scripts/SplineTrigger.cs

47 lines
1.1 KiB
C#
Raw Permalink Normal View History

2023-08-15 17:38:54 +03:00
using Dreamteck.Splines;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class SplineTrigger : MonoBehaviour
{
[SerializeField]
private LayerMask _layerMask;
2023-10-02 19:12:35 +03:00
[SerializeField]
private bool _triggerOnce = true;
2023-08-15 17:38:54 +03:00
2023-10-02 19:12:35 +03:00
private bool _triggered = false;
2023-08-15 17:38:54 +03:00
2023-10-02 19:12:35 +03:00
public UnityEvent<Collider> OnTriggerEvent;
public UnityEvent<Collider> OnTriggerStayEvent;
2023-08-15 17:38:54 +03:00
private void OnTriggerEnter(Collider other)
{
2023-10-02 19:12:35 +03:00
if (_triggerOnce && _triggered)
2023-08-15 17:38:54 +03:00
return;
if ((_layerMask.value & (1 << other.transform.gameObject.layer)) > 0)
{
2023-10-02 19:12:35 +03:00
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);
2023-08-15 17:38:54 +03:00
}
}
}