34 lines
673 B
C#
34 lines
673 B
C#
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
public class InteractTrigger : MonoBehaviour, IInteract
|
|
{
|
|
[Header("Events")]
|
|
[SerializeField] private UnityEvent onInteract;
|
|
|
|
[Header("Settings")]
|
|
[SerializeField] private bool triggerOnce = false;
|
|
private bool hasBeenTriggered = false;
|
|
|
|
public void OnInteract()
|
|
{
|
|
if (triggerOnce && hasBeenTriggered)
|
|
{
|
|
return;
|
|
}
|
|
|
|
hasBeenTriggered = true;
|
|
onInteract?.Invoke();
|
|
}
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (!other.CompareTag("Player"))
|
|
{
|
|
return;
|
|
}
|
|
|
|
OnInteract();
|
|
}
|
|
}
|