Continuous Jump | Rigidbody | Unity Game Engine


Jump.cs
using UnityEngine;

[RequireComponent(typeof(Rigidbody))]
public class Jump : MonoBehaviour
{
    public float jumpForce = 4;
    public float jumpInterval = 0.25f;

    Rigidbody rigidBody;
    float jumpTimer;

    void Awake()
    {
        rigidBody = GetComponent<Rigidbody>();
    }

    void Update()
    {
        jumpTimer += Time.deltaTime;
        if (Input.GetMouseButtonDown(0))
        {
            if (jumpTimer > jumpInterval)
            {
                jumpTimer = 0;
                rigidBody.velocity = Vector3.up * jumpForce;
            }
        }
    }
}