Unity Not Responding When Game Is Executed

I am creating a game based off of the classic Lunar Lander game and have encountered an issue. I have the following code attached to the player object, and Unity freezes and refuses to respond when I try to play the game. If anyone can figure out what is going wrong, that would be much appreciated. Thanks!

Code:

using UnityEngine;
using System.Collections;

public class VeerusMove : MonoBehaviour {
//moving is false, downSpeed is 0.0, and Rigidbody2d is shortened
bool moving = false;
float downSpeed = 0.0f;
public Rigidbody2D rb;

void Start()
{
//Shortens Rigidbody2d
rb = GetComponent ();
}

void Update ()
{
//adds a constant force
rb.AddForce (transform.up * downSpeed);
//Makes the constant force decrease when moving is false
while (moving = false){
downSpeed–;
}
//Sets moving to true while the spacebar is presed
if (Input.GetKey(KeyCode.Space)){
moving = true;
}
//Sets moving to false when the spacebar is released
if (Input.GetKeyUp(KeyCode.Space)) {
moving = false;
}
//Makes the constant force increase while moving is true
while (moving = true) {
downSpeed++;
}
}
}

Please use code tags when posting code to the forum for readability.

Here’s how Update() works:

Each script instance has its Update() called (if it has one) every single frame. The frame can not end until all scripts have finished their Update() (and LateUpdate() ).

If you have a while loop that never ends:

while (moving == false){    //Note that this needs to use the conditional operator '==' and not the assignment operator '='
downSpeed--;
}

then the whole process will hang when it reaches this point. Unity is waiting for this script instance to finish its Update() before moving on to the next instance, but it never will.

When you want to do something over time, usually the solution is to use coroutines, but I bet you could just change your while loops to if blocks to get the behavior you want. You’ll probably also want to change downSpeed--; to downSpeed -= Time.deltaTime; which changes it from decreasing by one each frame to decreasing by one each second. Make a similar change at downSpeed++; if needed.