2024-11-28 23:50:38 +08:00
|
|
|
|
using System;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace ZC
|
|
|
|
|
{
|
2024-11-29 17:35:04 +08:00
|
|
|
|
public class TriggerEvent : MonoBehaviour
|
2024-11-28 23:50:38 +08:00
|
|
|
|
{
|
2024-11-29 17:35:04 +08:00
|
|
|
|
[SerializeField] private string targetName;
|
2024-11-28 23:50:38 +08:00
|
|
|
|
private Action callback;
|
2024-11-29 17:35:04 +08:00
|
|
|
|
|
2024-11-28 23:50:38 +08:00
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
|
|
|
{
|
|
|
|
|
if (other.name == targetName)
|
|
|
|
|
{
|
|
|
|
|
callback?.Invoke();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-29 17:35:04 +08:00
|
|
|
|
public void SetData(Action callback, string target = "Player")
|
2024-11-28 23:50:38 +08:00
|
|
|
|
{
|
2024-11-29 17:35:04 +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
|
|
|
|
}
|
|
|
|
|
}
|