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

30 lines
621 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-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
{
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()
{
Destroy(this);
}
2024-11-28 23:50:38 +08:00
}
}