32 lines
895 B
C#
32 lines
895 B
C#
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
namespace RR.Game2D.Entities
|
|
{
|
|
[RequireComponent(typeof(Collider2D))]
|
|
public class EventTrigger : MonoBehaviour
|
|
{
|
|
[SerializeField] public UnityEvent OnEventTriggerEnter;
|
|
[SerializeField] public UnityEvent OnEventTriggerExit;
|
|
|
|
private Collider2D _col;
|
|
|
|
private void Awake()
|
|
{
|
|
if (!_col) _col = GetComponent<Collider2D>();
|
|
if (!_col) _col = gameObject.AddComponent<Collider2D>();
|
|
|
|
if (!_col.isTrigger) _col.isTrigger = true;
|
|
}
|
|
|
|
private void OnTriggerEnter2D(Collider2D other)
|
|
{
|
|
if (other.CompareTag("Player")) OnEventTriggerEnter.Invoke();
|
|
}
|
|
|
|
private void OnTriggerExit2D(Collider2D other)
|
|
{
|
|
if (other.CompareTag("Player")) OnEventTriggerExit.Invoke();
|
|
}
|
|
}
|
|
} |