Script isn't working. I can't seem to see any flaw in it though/

When I run my game with the script, the unity editor stops responding. When I comment the while loops in my script, it starts working again. I don’t understand what’s going wrong with it. My prediction is that the while loop is causing a problem and it might be an infinite loop but I have no idea where the problem is. Can I have some help on it please?

public int[] classroom_speakers = {3,3};
public string[] classroom_dialogues = {"Ow! My head...","What happened?"};
public Text speaker;
public Text speech;

private enum States {
	classroom, film,

private States myState;

int x;

void Start () {
	myState = States.classroom;

	void Update () {
		if (myState==States.classroom)		{classroom();}

void classroom () {

	int i = 0;
	//My prediction is that there's a problem here but I'm not sure what it is.

	while (i < classroom_dialogues.Length){
		if (classroom_speakers*==1)*
  •  	speaker.text="Me";*

if (classroom_speakers*==2)
if (classroom_speakers==3)
_ speaker.text=“Me(thinking)”;_
if (classroom_speakers==4)
_ speaker.text=" ";_
_ x = 0;*_

* while (x==0){*
* if(Input.GetKeyDown(KeyCode.Space))*
* {i++;*
* x=1;}*
* }*
* } *


The state of keypresses can only change between Update() calls, so if you enter the while loop and space wasn’t pressed magically just before that, you will never get out of the loop (you never end up in the i++ line)… because the endless loop prevents you from proceeding to the next Update where pressing space could be detected.

I don’t understand exactly what you are trying to do but to me it looks like the loops are not needed at all. Update will run repeatedly until you specifically stop it, so whatever text you are displaying can just be set whenever space is pressed

int i = 0;
void classroom () {
      if (Input.GetKeyDown(KeyCode.Space))
         if (classroom_speakers*==1)*

else if (classroom_speakers*==2)
else if (classroom_speakers==3)
else if (classroom_speakers==4)*

speaker.text=" ";