Files
cloud-mainworld/ufm cloud/Assets/#User/Community Modules/Scripts/#Scripts Backup/ObjectTrigger.cs._20260703-070904.txt
T
2026-10-22 12:41:09 +01:00

37 lines
1.1 KiB
Plaintext

using UnityEngine;
using UnityEngine.Events;
namespace CommunityModules
{
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();
}
}
}
}