using System; using UnityEngine; using RR.Game2D.Behaviour; namespace RR.Game2D.Entities { [RequireComponent(typeof(BoxCollider2D))] public class JumpPad2D : MonoBehaviour { [SerializeField] private float verticalBand = 0.75f; private BoxCollider2D _col; public Action PlayerJumped; private void Awake() { _col = GetComponent(); if (!_col.isTrigger) _col.isTrigger = true; } private void OnTriggerEnter2D(Collider2D other) { if (!other.CompareTag("Player")) return; PlayerController playerController = other.GetComponent(); Rigidbody2D playerRB = other.GetComponent(); if (!(Mathf.Abs(other.transform.position.y - _col.bounds.max.y) <= verticalBand)) return; Vector2 newPlayerVelocity = playerRB.linearVelocity; newPlayerVelocity.y = playerController.jumpVelocity; playerRB.linearVelocity = newPlayerVelocity; PlayerJumped?.Invoke(other.gameObject); } } }