My player velocity changing by itself?

So i am trying to make this geometry type game and just finished making a start menu not done though. The scene loads fine and everything works but when you start the game the player don’t jump when you click but when you open the player’s inspector everything starts working again. I have the script jump whenever you click and it used to work fine but now I keep have pause the game go to the inspector and then its normal. Can someone help also I can describe if someone is willing to help. my scene manager script is fine but I think there is something wrong with the player script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
public Rigidbody rb;
public GameObject Player;

private float time = 0.0f;
private bool isMoving = false;
private bool isJumpPressed = false;
public float Boost;
public float L;
public float F;

void Start()
{
    rb = GetComponent<Rigidbody>();
}

void Update()
{
    
  

    isJumpPressed = Input.GetMouseButtonDown(0);
}

void FixedUpdate()
{
    if (isJumpPressed)
    {
        
       
        // the cube is going to move upwards in 10 units per second
        rb.velocity = new Vector3(0, Boost, 0);
        isMoving = true;

        Debug.Log("jump");
    }

    if (isMoving)
    {
        // when the cube has moved for 10 seconds, report its position
        time = time + Time.fixedDeltaTime;
        if (time > 10.0f)
        {
            Debug.Log(gameObject.transform.position.y + " : " + time);
            time = 0.0f;
        }
    }
}
private void OnTriggerEnter(Collider other)
{
    if (other.tag == "Obstacle")
    {
        Destroy(Player);
    }
}

}

Well, one thing that stands out is that FixedUpdate is called by default 50 times per second unless you change the fixed time step in the time settings. So if you are getting 100 FPS for example, there will be 2 Update calls per 1 FixedUpdate call. So it is possible for you to press the button and have multiple frames pass before FixedUpdate is called and thus ‘isJumpPressed‘ will equate to false because that state resets on every update.


I would suggest that you make sure that the jump is going to happen by perhaps having another Boolean or an enum:


private enum JumpState
{
    Jumping,
    WaitingToJump,
    Grounded
}
private JumpState state;

private void Start()
{
    state = JumpState.Grounded;
}

private void Update()
{
    if(Input.GetMouseButtonDown(0) && state == JumpState.Grounded)
        state = JumpState.WaitingToJump;
}
private void FixedUpdate()
{
    if(state == JumpState.WaitingToJump)
    {
        rb.velocity = new Vector3(0, Boost, 0);
        state = JumpState.Jumping;
    }
    //when it becomes grounded again, state should become JumpState.Grounded again
}

I’ve left the grounding part up to you (maybe you want to check for a collision with the ground), but this should work.