What is the best way to manage the progression of a level?
Think of something like Tetris, or Fruit Ninja, where the player is given certain items to play with in a (let’s pretend for now) pre-determined order. Of course the basic algorithm to do this would be to do something like:
At a specific time, for example, 05:00, spawn item A. At 10:00, spawn Item B
or it could be
Spawn item A. When item A has been used, wait 2 seconds and spawn item B.
And one could of course hard-code these in, line by line. But is there a better way to handle these events?
I don’t believe Unity has anything built in to help this, so I imagine I’d have to write my own event system.
Would anyone have an example project they can show me?
Are there any extensions available that can help me with this?
you can code it and use variables that can be changed in the editor window for easier changes to the code from the inspector and each instance of the code in the scene can then be different to each other. You could also make a prefab of a spawner object with the code attatched even if its just an empty gameobject.
But you still need to write the code for it all to work.
For a cleaner solution add delegates and events to the picture.
Create the coroutine with a pre-defined yield wait at the end… OR create it at runtime with a custom function that has a Float input that you will assign to the wait.
Then tell the coroutine to run the event every tick.
Add spawns explosions etc. using the event system in C#.
Finally the most elegant solution - write an extensive system for spawning with an event that accept delegates that are runnable coroutines and automatically run them.
I personally would structure it something like that SpawnSystem.SpawnEvent += SpawnNpc(npc123, 5.0f,false);
Where npc123 is the npc var, 5.0f is the delay before the spawn and the last bool is if it should loop the spawn every 5 seconds or just run it once.
Ahh thanks jedybg, that seems like a good way, though I would also put in a fourth argument for telling the system where to spawn the objects.
I’m watching that tutorial now. I was actually hoping for an out-of-the-box solution, but now that I think about it, it may be better if I just write my own system (shouldn’t be too hard anyway)
My approach would be to persist your “states” into an xml doc and build either an FSM or list/map of triggers with their corresponding actions. So in the case of the latter, you might have something like:
Which would be polled and when you reach a particular state to spawn, invokes doAction(). Then in your xml config maybe you have something of the form:
Then create the appropriate actions and triggers (i.e. TimePassedTrigger, etc).