Why is this script bugging out inity

when i am testing this script unity crashes

#pragma strict

var IsMoving1 = false;
private var Moves1 = 1;
var IsMoving1R = false;

function Start ()
{
	IsMoving1 = false;
	Moves1 = 3;
	IsMoving1R = false;

}

function OnCollisionEnter ()
{
	if (IsMoving1R == true)
	{
		IsMoving1R = false;
		Moves1 = Moves1 -1;
	}
}

function Update ()
{
	if (Input.GetKeyDown(KeyCode.D) && IsMoving1 == false)
	{
		IsMoving1 = true;
		IsMoving1R = true;
		while (IsMoving1R == true)
		{
			transform.position.x = transform.position.x + 0.1;
		}
	}
}

Because you must put inside while loop condition for break loop, until there no break condition loop is infinite and make unity freeze. In your case better replace while loop with “if”:

 if (Input.GetKeyDown(KeyCode.D) && !IsMoving1) // replace "== false" with "!"
      {
          IsMoving1 = true;
          IsMoving1R = true;
          if (IsMoving1R) // no need to write "bool = true" just write "bool", and no need in while loop because update already make it for you
          {
              transform.position.x = transform.position.x + 0.1 * Time.deltaTime; //  multipling 0.1 by Time.deltaTime make sure you move 0.1 unit per second instead of per frame that vary and your movement is relied on fps of game.
          }