Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more..
    Dismiss Notice
  3. Dismiss Notice

How to create mission system like "Subway Surfers" or "Rider"

Discussion in 'Scripting' started by EfimMaksimov, Oct 5, 2020.

  1. EfimMaksimov

    EfimMaksimov

    Joined:
    May 16, 2020
    Posts:
    2
    I'm making an endless runner. I came up with several types of missions (blow up N asteroids, score N points, break the record). Different types can have different modifiers (in 1 game, N games in a row). A new mission must be issued after completing the previous one. How do I create such a system?

    Now I only understand that I need a base mission class and subclasses for each type, and events should be assigned to actions that are related to missions, but what objects should I subscribe to?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,769
    I wouldn't bother with inheritance in Unity3D: it almost always adds undesired brittleness, and for something this simple, it's just not necessary.

    Just make different scripts that implement your mission types, and then conditionally attach (or conditionally enable) only one script at a time when you are playing a level.

    Have a common pool of helpers such as "display milestones" and "complete mission" and that sorta thing, and have each variant of mission use those to trigger scene loads, activate UI, etc.

    By keeping it nice and loosely-coupled, it is easy to change as you develop the game, which is essential. Inheritance will needlessly bind you tightly into an architecture early, and greatly raise the cost of refactoring, for essentially zero benefit.
     
    PraetorBlue likes this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,769
    Here is a handy factory pattern for dynamically adding a Script and ensuring that it will ALWAYS have what it needs:

    Factory Pattern in lieu of AddComponent (for timing and dependency correctness):

    https://pastebin.com/euGb7t3k
     
  4. EfimMaksimov

    EfimMaksimov

    Joined:
    May 16, 2020
    Posts:
    2
    As I understand it, you suggest attaching a script of the current mission type at the beginning of each run, which will subscribe to events related to its type?
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,769
    However you want to connect it: you can use a static reference to an interface that is shared by all of them (a form of inheritance that is far less brittle), or else just use .SendMessage() to send messages to that script.
     
  6. meghanvasquez87

    meghanvasquez87

    Joined:
    Jun 17, 2022
    Posts:
    1
    Hey there!
    Missions are challenges that require the player to complete to increase their multiplier or to get a Super Mystery Box (only when multiplier has reached x30). You can find it at the top-left part of your screen when not playing. Pausing your game can also lead you to it. Each mission set has 3 missions.

    Quickly create different programs to execute various mission kinds, yet only connect or optionally activate one code at a period while completing a game. Get lightning link free coins a reserve pool of assistance, such as display milestones and "complete mission," have each variation of mission use these scene loading and activation.
     
    Last edited: Jun 18, 2022