using UnityEngine; public class Jump : MonoBehaviour { Rigidbody rigidbody; public float jumpStrength = 2; public event System.Action Jumped; [SerializeField, Tooltip("Prevents jumping when the transform is in mid-air.")] GroundCheck groundCheck; void Reset() { // Try to get groundCheck. groundCheck = GetComponentInChildren(); } void Awake() { // Get rigidbody. rigidbody = GetComponent(); } void LateUpdate() { // Jump when the Jump button is pressed and we are on the ground. if (Input.GetButtonDown("Jump") && (!groundCheck || groundCheck.isGrounded)) { rigidbody.AddForce(Vector3.up * 100 * jumpStrength); Jumped?.Invoke(); } } }