Currently i am developing one puzzle type casual game where user have to collect key avoiding obstacles.
All the levels have different gameplay, different number of enemy, different number of keys etc.
For example 1st level has 3 enemy that are go from left to right and right to left.
2nd level has 3 enemy that move in circle to same point.
3rd level has enemy that has random direction to move.
etc.
so i have approximately 120 levels and if i design 1st level it need different script and 2nd need another and so on…
maybe some level need more than one script for each object.
so i think you got my problem.
How can i improve it ?
can i use 1 script per level that control all the object in scene ? how ?
My suggestion is to try and find common behaviours that can be adjusted based on variables, for example:
Behaviour: Patrol
Variables: Vector2 limit1, limit2
Routine: Moves character towars limit1, then change to go to vector2, and vice versa.
Behaviour: KillOnContact
Routine: if collided with Player, kill player.
Behaviour: Die
Variables: string dieTag
Routine: if collided with object having dieTag, kill this.
Then you can mix and match different objects with different behaviours to achieve your unique enemy/chalklenge in a given stage. Also, you can use different scenes for each stage (not the optimal solution, but easy one)
I also have thought about it.
But if there is any other way that help me to make it more easy.
I thought that i can create one script called Level1Controller and it have public variable of all enemy and other thing and all are controlled in same script.
I doubt that in all your 120 levels will have completely unique enemies on each state. There will be repeats.
There will be multiple times where enemy will display behavior seen before on other levels. Multiple levels will hav nemies that move left to right, or enemies that move in a circle and so on.
Make a class for that enemy. Make them work independently, without relying on existence of “level script”. They don’t need a “level script” in the first place.
Then store enemy configuration as a prefab.One prefab per level, perhaps.
Then make one “gameplay script” used by all levels.
Because the only thing “level script” does is counting player lives and displaying gameover screen, and that’s the same thing for all levels.
If you’re doing a “space invaders” type of the game, here’s what’s happening.
There’s a script that counts score, lives and displays gameover screen.
Player script fires projectiles and explodes when hit by enemy.
Enemies explode when hit by projectiles.
Enemies move in different ways.
So you need 3 scripts for ALL levels + few more scripts for differet enemy movement types. It doesn’t matter how many levels are there, the script will keep doing the same thing.