Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Best Way to Implement A Mission System

Discussion in 'Scripting' started by SevenBits, Dec 26, 2011.

  1. SevenBits

    SevenBits

    Joined:
    Dec 26, 2011
    Posts:
    1,953
    Hello All,

    I'm currently programming a First Person Shooter. I'm looking for the best way to implement the missions. This includes objectives, briefings, etc. I have tried several times to implement a system, however, it is difficult to code and not portable or extendable. I do not want to use any visible scripting tools, as they increase my project size and as this is a side project I have a very limited budget.

    Does anyone know a manageable system? I'd prefer an object oriented system to avoid hassles, and so I can attach various scripts to game objects to assign their roles.

    Has anyone coded something like this before? I'd very much appreciate assistance.

    SevenBits
     
  2. _zeta

    _zeta

    Joined:
    Dec 24, 2011
    Posts:
    99
    heres one super mega powerfull uber tool ------ its called ---- HUMAN BRAINS - USE THEM!
    write your code, none of those assets will meet your needs, make it your self!
     
  3. Ted-de-Munnik

    Ted-de-Munnik

    Joined:
    Mar 13, 2011
    Posts:
    119
    Just for reference:
    A good implementation, in my mind, would be a base class for each mission that contain basic information about it, like completion status.
    Then each mission, or kind of mission(e.g. Capture x), you create new derrived classes of this. you can then accept all missions in the same way, for instance with mission.Execute(); while the actual mission code is different.

    I don't have time, and won't, just give you a complete piece of code. Just look at the microsoft C# documentation to find information about deriving classes.

    -- Ted de Munnik
     
  4. SevenBits

    SevenBits

    Joined:
    Dec 26, 2011
    Posts:
    1,953
    I actually know about deriving classes. What I first did was create a class called MissionController and created an extension called MissionOneUpdater for the first mission. The program contained a method called UpdateMission() that would update the mission and perform any necessary tasks, such as playing a narrative audio clip. The problem was I couldn't think of a way to do this when an external object was destroyed.

    I nearly tried almost twenty different approaches to the problem, all similar; none working.
     
  5. npsf3000

    npsf3000

    Joined:
    Sep 19, 2010
    Posts:
    3,830
    Sounds like a fairly simple thing to do - what exactly is your problem?
     
  6. Ted-de-Munnik

    Ted-de-Munnik

    Joined:
    Mar 13, 2011
    Posts:
    119
    I think this will be very usefull for that problem:
    http://www.everyday3d.com/blog/index.php/2010/10/04/c-events-and-unity3d/

    You can compare the destroyed item was the one you need, or else do nothing. This would also work for a destroy 10 boxes kind of mission. This is de way I would do this, not sure if it's the "best" one.
     
  7. SevenBits

    SevenBits

    Joined:
    Dec 26, 2011
    Posts:
    1,953

    Looks like it might work for what I'm doing. Never thought to do it using delegates... interesting. I'm going to try that out. Thanks for sharing!
     
  8. Ericool

    Ericool

    Joined:
    Nov 25, 2014
    Posts:
    3
    Do a class mission that has all properties you need . Make serializable. Try xml and save an array of mission then load it in the application . Make a for loop on each of them calling the abstract method updatemission for instance. The xml file contains missions you have not completed yet.
     
    Kiwasi likes this.
  9. fire7side

    fire7side

    Joined:
    Oct 15, 2012
    Posts:
    1,819
    I would just send a message to a manager when an ondestroy was called for the mission object, or whatever, when an object was triggered, etc. If you make it from a generic class or something, it will probably feel generic in a short while. The missions should be individual.
     
    Last edited: Dec 20, 2014
  10. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    This is a complex topic. First up there is no best way to do anything in coding. The best way depends a lot on your needs and the scale of the project. That said here is a mental dump of ideas to play with.

    I would suggest creating a class for your mission manager. This can contain a list of all currently active missions, and call there various interfaces from there.

    Create a mission class (or multiple) that implements interfaces for everyting you need. Use an Enumerator and MoveNext to cycle through objectives. Keep this class relatively generic. Give it properties for everything you need, but don't hard code any mission data.

    Create an objective class that contains the relevant details of an objective. This maybe the place to contain your checking for objective completion stuff.

    Don't hardcode any mission data. Use a serialisation technique to load this at run time. If you want you can also create a small mission editor to eliminate mistakes in writing the data files. You'll find the level/map editors released with most games were actually built to help the developers make levels, and got shipped as an afterthought.
     
    songoku45 likes this.