While Statement Causing Unity to Crash,While Statement Freezing Unity

void Update()
{
horizontalMove = Input.GetAxisRaw(“Horizontal”) * runSpeed;
while (Input.GetKeyDown(“d”))
{
Debug.Log(“d”);
move = GetComponent();
move.velocity = velocity;
velocity = Vector2.zero;
GetComponent().velocity = new Vector3(3, 0, 0)

    }
    while (Input.GetKeyDown("a"))
    {
        GetComponent<Rigidbody2D>().velocity = new Vector3(-3, 0, 0);
    }

}

Not sure why this code is crashing unity, I know its because it turns into a infinite loop but im not sure whats causing it

,I am trying to make it so when I hold down the key the player continues moving, right now the player just moves a little. When using a while statement it freezes. Screenshot by Lightshot

Why would you want to do a while-loop to set a value to velocity?

The loop will never end because if Input.GetKeyDown(“a”) is true at one time it will never become false, since no other code will run during the loop. You have to let Update() exit to let Input.GetKeyDown() be updated and then check it again in the next Update(). But if you want to check if the key is pressed you should use Input.GetKey() instead.

Use:

if(Input.GetKeyDown("a"))
{
    //...
}