Why is my Script Crashing Unity!??!

I changed a few things with the script - Mostly, trying to disable the left/right movement keys, when against the left/right wall, as it was causing my object to eventually flip if held down too long.

After the change, touching the walls, now crashes Unity.

I have NO idea why. please help!

using UnityEngine;
using System.Collections;

public class playerMovement : MonoBehaviour
{
    public float speed2D;
    public float speed3D;
    public float jumpSpeed;
    private bool jump;
    private int jumpAllower;
    private bool moveRight;
    private bool moveLeft;
    

    void Start()
    {
        jumpAllower = 1;
    }

    void FixedUpdate()
    {

        moveRight = Input.GetKey(KeyCode.D);
        moveLeft = Input.GetKey(KeyCode.A);

        jump = Input.GetKeyDown(KeyCode.Space);
    
 
        float moveHorizontal = Input.GetAxis("Horizontal");
        
        

        

        Vector3 movement2D = new Vector3(0.0f, moveHorizontal, 0.0f);
        Vector3 jumpSize = new Vector3(0.0f, 0.0f , -1.0f);





        if (jumpAllower == 1)
        {
            if (moveRight == true)
            {
                jump = false;
            }
            if (moveLeft == true)
            {
                jump = false;
            
        }  
           

            
        {
            Debug.Log("Jump Possible");
            gameObject.transform.Translate((movement2D * speed2D) * Time.deltaTime);
                if (jump == true)
                {
                Debug.Log("I jumped");
                gameObject.transform.Translate ((jumpSize * jumpSpeed) * Time.deltaTime);
                jumpAllower = 0;
                }
        }
            }


    }
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("Ground"))
        {
            jumpAllower = 1;
        }
        while (other.gameObject.CompareTag("Right Wall"))
        {
            Debug.Log("Hitting Right");
            moveRight  = false;
        }
        while (other.gameObject.CompareTag("Left Wall"))
        {
            Debug.Log("Hitting Left");
            moveLeft = false;
        }

    }


}

You have infinitie (or too long) while-loops. They will max out your CPU and thus freeze the program (until they resolve). Not sure if it actually affects your CPU, but the program will freeze/crash since it can’t break out of the loop.

You should really only run very short while-loops or run them in a Coroutine where you can “freeze” the while-loop with a “yield return new WaitForSeconds(1f)” (wait one second before continuing the iteration).

Instead of using a while loop, you can use “OnTriggerExit” to set “moveRight” and “moveLeft” to true once the player leaves the collision. There is also “OnTriggerStay,” which performs an action every frame an object is in a collision.