Singleplayer option for multiplayer based game

Heyyy

I’ve made a functional multiplayer sandbox game but I but the main game in multiplayer and I wish to have a singleplayer mode but I don’t know how to have singleplayer without having to remake the entire game and then everytime I made a edit I would have to do the same thing in singleplayer any ideas please help thank you!

Assuming that the multiplay game mode is locally hosted, for a single player mode, just start a game and allow only 1 player to join, the local player.

I’m trying that but the scripts I’m trying to create a server and join it are failing @Jos-Yule know any scripts?

I don’t know how you have setup your Network stuff, but i simply call StartHost() on my Lobby Manager class, and that works for me. It creates both sides (the Server and Client) and i can set the max-users to 1, to ensure that only the local play can connect, also just not creating a match/lobby or however you advertise your games, so others can’t see or join it.

ive got a network manager and no lobby manager @Jos-Yule

So that has a StartHost() method on it too. How do you normally start a game? What is the sequence of method calls/settings?

I have a Gameobject called NetworkManager with a networkmanager and network hud components the hud allows buttons to appear on screen and you can click local host or matchmaking or join client

I’m trying to create a server by

using UnityEngine;
using System.Collections;
using UnityEngine.Networking;

public class StartSinglePlayer : NetworkBehaviour {
    NetworkClient myClient;
    public GameObject playerPrefab;


    // Use this for initialization
    void Start () {
   
    }
   
    // Update is called once per frame
    void Update () {
   
    }

    public void StartWorld(){
        Application.LoadLevel ("Main");
        Network.InitializeServer (2,7778, false);
        MasterServer.RegisterHost ("TEST","TEST","Dunno");
        print ("Created server.");
   





    }
    void OnServerInitialized(){
        Network.Connect ("192.168.1.80",7778);




    }

    void OnPlayerConnected(){
        Network.Instantiate (playerPrefab,new Vector3(0f,100f,0f),Quaternion.identity,0);
    }

ah ok. You are using the raw Network API. I’m not sure what will work in this case. But, the Network.Connect should be calling 127.0.0.1, not 192.168.1.80. (127.0.0.1 is the loopback address - it always points to the machine it is on). And, you don’t want to call the MasterServer.RegisterHost() - that isn’t required if you are doing a local game.

yes sorry I have tried 127.0.0.1 it said the same thing

And i’m not sure you can actually call both .Connect() AND .Instantiate() with the Network API, now that i think about it.

So, i’m at the end of my available help here - i haven’t worked with the raw Network API since the new UNet stuff came out, which makes a lot of this easier. Sorry! I know there are ways to do it, just don’t have that in my brain right now. Good luck!

well it dosnt actually connect it just says cannot connect are you sure the server is connectable

ok thanks for the help goodbye!