Case States in c#??

I was following a tutorial but on the tutorial it says this is fine but i keep getting an error:/

using UnityEngine;
using System.Collections;

public class MobGenerator : MonoBehaviour {
	public enum State {
		Idle,
		Initialize,
		Setup,
		Actions
	}
	public GameObject[] mobPrefabs;         //an array to hold all the prefabs of mobs we want to spawn
	public GameObject[] spawnPoints;             //this array will hold a referance of all the spawn points
	
	public State state;                   //This is our local state that holds our local state
	
	// Use this for initialization
	void Start () {
		while(true) {
			switch(state) {
				case State.Initialize;
					break;
				case State.Setup;
					break;
				case State.Actions;
					break;
				
			}
		}
	
	}
	
}

And what is the error you're getting?

2 Answers

2

case State.Initialize;

should be

case State.Initialize:

And so on. The cases end in a colon, not a semicolon.

You should replace the ‘;’ at the end of each case statement with a ‘:’ like this:

     switch(state) {
      case State.Initialize:
          // code for Initialize goes here
          break;
      case State.Setup:
          // code for Setup
          break;
      case State.Actions:
          // code for Actions
          break;
    }