# Mission system for a FPS game to force the player into following the storyline

Lately I've been working on a FPS game with a storyline in unity and I've encountered something that has been making my head explode for days. My objective is to be able to force the player to do a certain objective before being able to continue the game and to also give the new missions straight after the player has completed the past ones.

To help the player out I've created a panel with the description of the mission so that the player can check it out whenever he wants to. I've already created some code of my own for one mission but it seems to be a mess, I'm sure I should have different scripts for different things so that I didn't need to repeat code so much when I'm about to create a new mission script.

My problem is that I don't have the skills yet to do and I would like some suggestions: how could reduce my code and how I could create a universal script that would be able to recognize which missions are done and which are not, instead of doing it over and over again in every single mission script?

I'm kinda of new to unity and I've never posted to stack overflow so if I made any mistakes I'm sorry.

Extra information: the storyline is a linear, what I mean by that is that it doesn't give the player a choice to change it, it will always be the same and the quests/missions are here to force the player into following it. For example, the first mission is for the player to go down stairs and turn on two batteries. The second mission is for the player to kill a certain amount of enemies that appear right after.

There is never just one solution for a problem. And this is one of those problems where you can ask 10 different programmers and will get 20 different answers.

First of all, what are our requirements? The requirements I would want for such a system are:

• Each mission should be a separate asset. No one humongous script including the whole story of the game.
• Each mission should be separately testable. I want to be able to place the player character in a room and then test a specific mission as quickly as possible.
• I would like to script each mission in C# (or perhaps in Bolt), because I won't yet know all the things I want missions to be able to do.
• Follow the KISS principle. Avoid building complex systems on top of Unity. Work with the engine instead of against it.

One solution I would try for this problem is this:

1. Create a folder "Missions" in your assets.
2. For each mission, create an empty prefab and a script with the same name. When the game is linear, I would consistently name them Mission_01 to Mission_99. You might want to follow these names with a short description of the mission so you have an easier time navigating them (e.g. Mission_17_TalkToBob). Attach each of those scripts to the corresponding prefab.
3. Implement each of those scripts as follows:
• An inspector-accessible variable for the prefab for the next mission
• The Start-method sets up anything which needs to happen at the beginning of the mission. Update the UI to show the next objective, spawn things which are specific to the mission, and so on. (Although mission-specific game objects could also be implemented as children of the mission prefab)
• The Update-method checks if the fulfillment conditions of this particular mission are met. Both batteries are in the on-state, all enemies are destroyed, etc. When that's the case, the mission script destroys its own game object and instantiates the prefab for the next mission.
1. Add the prefab for the first mission (or the one you want to test) to the scene
• Thank you so much, I'll try to follow it, I just have a question, I'll create all the missions by separate scripts right? Should I create a script that will be able to manage all the missions and put them by order (when it completes one mission it redirects immediately to the next one) or should I do that in the code of the missions itself, like in the code of the mission_01 I would put something so when completed it would go to the mission_02 Apr 5 at 9:29
• @Estronduu This architecture does not require a centralized MissionManager. Each script is its own mission manager and is responsible for instantiating the mission manager for the next mission when it's fulfilled. Apr 5 at 9:30
• Okay I think I got it nvm, I should add a space in the inspector for the prefab of the next mission and integrate the mission transition in the code of the mission. Once again thank you so much it was really helpful Apr 5 at 9:33
• @Estronduu Yes, that's what I wrote in point 3. Apr 5 at 9:36
• I just have one last question, its still related to the same topic, I used to have a seperate script that took care of the panel (the one i said that opens once the player presses a certain key), should i delete it and integrate it into the code of every mission (because once you complete a mission the text has to change) or should i keep it and make changes so the text changes by a seperate script? Apr 5 at 10:25