best way to control overall game play?

hello everyone
I’ trying to write a globe script in c# to control the overall execute order, the project i’m working is a educational software, whose every steps must be executed one by one, first thing i realize is using delegate like :

public class demo : MonoBehaviour {

	public delegate void OnStepChangeHandler(int step);
	public static event OnStepChangeHandler OnStepChange;

	//step
	public int Step{get;private set;}
	//to make sure step is changed
	private int stepCache = 0;
	public void SetStep(int i)
	{
		if(stepCache!=i)
		{
			//if step is changed, fire the overall event
			this.Step = i;
			OnStepChange(this.Step);
		}
		this.stepCache = this.Step;

	}
}

and other scripts will listen to the event, as camera:

void OnEnable()
	{
		demo.OnStepChange += moveCam;
	}
	void OnDisable()
	{
		demo.OnStepChange -= moveCam;
	}
	void moveCam(int step)
	{
		switch (step)
		{
		case 1:
			//move camera
			break;
		case 2:
			//move camera
			break;
		}
	}

it’s works , however, i realize it‘s maybe not a good idea to control overall steps by events: anyone can change overall steps and the whole game logic becomes a mess

sorry, i gonna work, update later

Hi, there!

It sounds like a game quest, probably you could use ready solution for creating quests from Asset Store, I think, there are could be some impletentations.

thanks Patico,but what i need is actually a game flow overall controller , not a quest system

so i think i could use corouting, like:

bool stepComplete = false;
	IEnumerator Start ()
	{
		yield return StartCoroutine(step1);
		yield return StartCoroutine(step2);
		//...
	}
	IEnumerator step1()
	{
		while(!stepComplete)
		{
			//wait for all other scripts complete
			//what codes here ?
		}
		yield return null;
	}

any better solution?
(if so, what’s the best expression?)
thanks a lot.

What you described is a Finite State Machine (FSM). If you don’t want to follow the tutorial in that link, you can pick up FSM code or visual scripting tools on the Asset Store.