using UnityEngine; public class HoleGoalTrigger : MonoBehaviour { [Tooltip("Optional: assign the ball rigidbody or leave empty to accept any Rigidbody with tag Ball.")] public Rigidbody ballRigidbody; [Tooltip("If true, checks tag 'Ball' when ballRigidbody not assigned.")] public bool requireBallTag = true; public System.Action OnBallScored; private void OnTriggerEnter(Collider other) { if (ballRigidbody != null) { if (other.attachedRigidbody == ballRigidbody) { OnBallScored?.Invoke(); } return; } if (other.attachedRigidbody == null) return; if (requireBallTag) { if (!other.CompareTag("Ball")) return; } OnBallScored?.Invoke(); } }