HAARFTE/Assets/DemoGame/GameScript/Hotfix/Other/TriggerEvent.cs

36 lines
766 B
C#
Raw Normal View History

2024-11-28 23:50:38 +08:00
using System;
using UnityEngine;
namespace ZC
{
public class TriggerEvent : MonoBehaviour
2024-11-28 23:50:38 +08:00
{
[SerializeField] private string targetName;
2024-11-28 23:50:38 +08:00
private Action callback;
2024-12-04 21:28:15 +08:00
private void Awake()
{
gameObject.SetActive(false);
}
2024-11-28 23:50:38 +08:00
private void OnTriggerEnter(Collider other)
{
if (other.name == targetName)
{
callback?.Invoke();
}
}
public void SetData(Action callback, string target = "Player")
2024-11-28 23:50:38 +08:00
{
2024-12-04 21:28:15 +08:00
gameObject.SetActive(true);
this.targetName = target;
2024-11-28 23:50:38 +08:00
this.callback = callback;
}
2024-12-02 17:42:16 +08:00
public void Dispose()
{
2024-12-04 21:28:15 +08:00
gameObject.SetActive(false);
2024-12-02 17:42:16 +08:00
}
2024-11-28 23:50:38 +08:00
}
}