Files
2026-04-30 00:53:30 +02:00

23 lines
506 B
C#

using UnityEngine;
using UnityEngine.Events;
public class SimpleTrigger : MonoBehaviour
{
public Rigidbody2D triggerBody;
public UnityEvent onTriggerEnter;
void OnTriggerEnter2D(Collider2D other){
//do not trigger if there's no trigger target object
if (triggerBody == null) return;
//only trigger if the triggerBody matches
var hitRb = other.attachedRigidbody;
if (hitRb == triggerBody){
onTriggerEnter.Invoke();
}
}
}