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. Dismiss Notice

How can I make a single player game and a multiplayer game?

Discussion in 'Multiplayer' started by Skyflamme, Mar 1, 2022.

  1. Skyflamme

    Skyflamme

    Joined:
    Aug 12, 2020
    Posts:
    33
    Hello,

    I have some (hopefully simple) questions. I'm trying to make a simple single player game and it would be perfect for an additionel multiplayer, but (ps. im using Mirror) can I just use the same scripts with "Monobehaviour" instead of "Networkbehaviour"? Or do I have to duplicate all?

    Thanks if you respond,
    Skyflamme.
     
  2. e_Zinc

    e_Zinc

    Joined:
    Oct 31, 2019
    Posts:
    16
    I would just use NetworkBehaviour for anything that needs to be networked. Mirror should work like a singleplayer game if you code it like a multiplayer game by hosting your own server and connecting to it as a client (listen server). You're just sending packets to yourself at that point. Duplicating the code would seem like a massive hassle, especially if you're trying to fix bugs.
     
    MrBigly likes this.
  3. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    322
    E_zinc is correct but if you're also just getting started maybe check out Fish-Networking. It offers a lot more features, it's also free, and I've been told many times by people coming from Mirror that Fish-Networking is easier to use.

    Also, Fish-Networking has a true offline mode that won't open any ports but it still runs off your multiplayer code. This lets you write code once for offline or online use.
    All links can be found on the documentation
    https://fish-networking.gitbook.io/docs/

    If you've any questions either way let me know.
     
  4. e_Zinc

    e_Zinc

    Joined:
    Oct 31, 2019
    Posts:
    16
    That looks really awesome. Also, if you're the guy that made all the First Gear Games stuff -- thank you! Your addons have been lifesavers.
     
    Punfish likes this.
  5. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    322
    I am, thank you! Most of those are built into FishNet for free as well, others are available to patrons and everyone gets grandfathered so there's no price increase for people leaving Mirror.
     
  6. PekkaCreeper

    PekkaCreeper

    Joined:
    Mar 17, 2020
    Posts:
    1
    So i should make 2 player movement scripts, one with the networkbehaviour and an other one with out for the singleplayer
     
  7. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,731
    That's exactly NOT what he is suggesting.

    The easiest solution, as already mentioned, is to use Fish Networking (or PUN Fusion) and make use of their offline mode which allows you to use the same code for both single player and networked modes.