Search Unity

Game Mission Manager

Discussion in 'General Discussion' started by GadOleg, Jan 15, 2022.

  1. GadOleg

    GadOleg

    Joined:
    Nov 13, 2019
    Posts:
    58
    Hello!
    I'm creating a game that has missions. Unfortunately, I found little information on the Internet about the organization of solving this kind of problem. I went my own way:
    1) Any plot of the game boils down to the execution of chains of missions that can be combined, for example, into chapters. Each chapter for the work of the magazine should have a title and description and a list of missions:
    Code (CSharp):
    1. public class Chapter{
    2.     public int CurrentChapter;
    3.     public string ChName;
    4.     public string ChDescription;
    5.     public List<Mission> actionMissions = new List<Mission>();
    6.     public Chapter() { }
    7. }
    Each mission must also have a name, description, status completed or not, status active now or not, as well as a list of game active items
    Code (CSharp):
    1. public class Mission{
    2.     public int Number;
    3.     public string Name;
    4.     public string Description;
    5.     public bool Completed;
    6.     public bool Active;
    7.     public List<ActionObject> actionOBJ = new List<ActionObject>();
    8.     public Mission() {}
    9. }
    Each game active item must have a link to the GameObject, the type of action, the state of activity
    Code (CSharp):
    1. public class ActionObject{
    2.     public GameObject WorkPiece;
    3.     public TypeOfAction WhatToDo;
    4.     public bool Deactivate;
    5.     public ActionObject(){
    6.         Deactivate = false;
    7.     }
    8. }
    In my experience of games, I can say that there are the following types of actions: get, take, deliver, kill or destroy.
    Code (CSharp):
    1. public enum TypeOfAction{
    2.     GetThere,
    3.     Take,
    4.     Deliver,
    5.     Kill
    6. }
    How does this thing work: I independently wrote a procedural generator for the appearance of game objects, which creates objects near the player's visibility zone of the environment. When a game object appears from the generator in Awake(), it looks for its position in the mission manager (if there is one [which is set by 3 variables]) and specifies the type of action
    Code (CSharp):
    1. public class GeneratorOBJ
    2. {
    3.     public GameObject Monster;
    4.     public int Chamber;
    5.     public int Mission;
    6.     public int ActiveOBJ;
    7.     public TypeOfAction WhatToDo;
    8.  
    9.     public GeneratorOBJ() { }
    10.     public GeneratorOBJ(GameObject _monster)
    11.     {
    12.         Monster   = _monster;
    13.         Chamber   = -1;
    14.         Mission   = -1;
    15.         ActiveOBJ = -1;
    16.     }
    17. }
    Activating a game object event when completing a mission is simple for all types except "Take", I'm stuck with it now.
    In this connection, I want to ask who knows other ways to solve my problem?
    Are there ready-made solutions?
     
  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,566
    Your game should track when player kills something, or when player picks things up.

    A delivery mission could either listen to mission object being picked up, or check player's inventory from time to time to see if the key item is present. Additionally pickable mission object could directly increase mission counter while it is being picked up.
     
  3. kittik

    kittik

    Joined:
    Mar 6, 2015
    Posts:
    565
    I suggest objects that can be picked up, or the actor picking up the item invoke an action. The game manager should subscribe to actions when the next mission is setup and then unsubscribes once the mission is complete.

    Actions on pickup, and other in-game events would be helpful in all manner of scenarios, so it could be subscribed to for other parts of your project.
     
  4. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    6,013

    Almost everything in games can be solved with two simple mechanisms: state machines and events.

    In all my games and assets there is the concept of the Game State for the entire game. It solves numerous coordination problems - menu open/close, input enabling/disabling, HUD enabling/disabling, time and audio pauses, etc. The game is always in a specific game state, and this game state determines what can happen in the scene and what can't.

    For missions, again you need a state machine - START wait for the player to go somewhere CHANGE STATE trigger this cinematic CHANGE STATE wait for the player to kill this boss CHANGE STATE show 'mission complete' and make the character jump in the air etc. Moving from one state to the other occurs through events.

    Then you can easily create all kinds of new missions by stacking states one after the other, connected by events. Rather than random scripts and bits of code fighting for control of the scene.
     
    NotaNaN likes this.