Jumping not working (840986)

Hi. Below is a character controller for my first ever game in unity, written in c#. I have created a variable to know when to reset my current velocity so that if I were to fall off something, I won’t zip to the ground as my velocity keeps getting lower and lower. However, this variable is not changing based on when I tell it to. e.g. in the line:

if(Input.GetButtonDown("Jump") && isGrounded)
            velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
            isJumping = true;

It just won’t change to true no matter what I do. I’m unsure if I have put a line later that immediately sets it to false or if there is an issue in my if statement. I know that this statement definitely works, as it causes me to still jump and I have checked with a Debug.Log() statement.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class playermovementnew : MonoBehaviour
    {
        public CharacterController controller;
        public Rigidbody rb;
        public Transform player;
        public float speed = 12f;
        public float gravity = -9.81f;
        public float jumpHeight = 3f;
        public float relativeJumpHeight = 5.5f;
        float scenex;
        float sceney;
        float scenez;
        float maxJumpHeight;
        public Transform groundCheck;
        public float groundDistance = 0.4f;
        public LayerMask groundMask;
      
        Vector3 velocity;
        bool isGrounded;
        bool isJumping;
      
        void Update()
        {
            isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
          
            scenex = player.position.x;
            sceney = player.position.y;
            scenez = player.position.z;
            maxJumpHeight = sceney + relativeJumpHeight;
            float x = Input.GetAxis("Horizontal");
            float z = Input.GetAxis("Vertical");
            Vector3 move = transform.right * x + transform.forward * z;
            controller.Move(move * speed * Time.deltaTime);
            if(Input.GetButtonDown("Jump") && isGrounded)
            {
                velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
                isJumping = true;
            }
            if (isJumping)
            {
                if (sceney >= maxJumpHeight)
                {
                    isJumping = false;
                }
            }  
            if (isGrounded && velocity.y < 2f);
            {
                if (isJumping = false)
                {
                    velocity.y = -2f;
                }
            }
            velocity.y += gravity * Time.deltaTime;
            controller.Move(velocity * Time.deltaTime);
        }
    }

Looks like the above code calls .Move() twice, which is apparently (nowadays) a no-no for the CharacterController, even though that is actually presently in the example code that Unity offers for CharacterController.

It used to be okay, but in the past 2 years or so, it started to break how the isGrounded testing worked.

I wrote about this before: the Unity example code in the API no longer jumps reliably. I have reported it. Here is a work-around: