Files
2026-10-22 12:41:09 +01:00

37 lines
1.1 KiB
C#

using UnityEngine;
using UnityEngine.Events;
namespace UFMTESTING1
{
public class ObjectTrigger : MonoBehaviour
{
public UnityEvent OnEnter;
public UnityEvent OnExit;
[Header("Optional (Ingored if empty)")]
[SerializeField] private string _objectName = "";
[SerializeField] private string _objectTag = "";
private void OnTriggerEnter(Collider other)
{
bool isNamePass = _objectName.Length == 0 || other.gameObject.name == _objectName;
bool isTagPass = _objectTag.Length == 0 || other.gameObject.CompareTag(_objectTag);
if (isNamePass && isTagPass)
{
OnEnter?.Invoke();
}
}
private void OnTriggerExit(Collider other)
{
bool isNamePass = _objectName.Length == 0 || other.gameObject.name == _objectName;
bool isTagPass = _objectTag.Length == 0 || other.gameObject.CompareTag(_objectTag);
if (isNamePass && isTagPass)
{
OnExit?.Invoke();
}
}
}
}