Beispiel #1
0
    // Use this for initialization
    void Start()
    {
        // setup reference to networkVariables
        nvs    = gameObject.GetComponent("networkVariables") as networkVariables;
        myInfo = nvs.myInfo;

        // add us to the player list
        nvs.players.Add(myInfo);

        // get server version
        serverVersion = nvs.serverVersion;              // maybe set the server version to the map name?
        // get server name
        string serverName = nvs.serverName + ": Lobby";

        // serverComment also holds extra info about the server
        serverComment         = new ServerComment();
        serverComment.NATmode = nvs.NATmode;
        serverComment.comment = "This is a comment about the server";
        serverComment.level   = "level_full";           // only use this one since it's the only one set up atm

        // Use NAT punchthrough if NATmode says to
        Network.InitializeServer(31, 11177, nvs.NATmode != 0);
        Debug.Log(serverComment.toString());
        //MasterServer.updateRate = 5; - not needed anymore since Unity doesn't understand networking
        MasterServer.RegisterHost(serverVersion, serverName, serverComment.toString());

        // get game state
        gameHasBegun = nvs.gameHasBegun;

        // go into the lobby
        gameObject.AddComponent <netLobby>();
    }
Beispiel #2
0
    void StartGame()
    {
        Component.Destroy(GetComponent("netLobby"));

        // lookup from level list will be added here
        Application.LoadLevelAdditive("level_full");

        /*
         * // don't let anyone else join - this doesn't work (and hasn't since 2010 -_-)
         * MasterServer.UnregisterHost();
         * // instead make up a password and set it to that
         * string tmpPwCuzUnitysShit = "";
         * for (int i=0; i<10; i++) {
         *      tmpPwCuzUnitysShit += (char)(Random.Range(65,90));
         * }
         * Debug.Log(tmpPwCuzUnitysShit);
         * Network.incomingPassword = tmpPwCuzUnitysShit;
         */

        string serverName = nvs.serverName + ": Game started";

        serverComment.comment = "This is the server comment";
        serverComment.level   = "level_full";
        serverComment.locked  = true;
        MasterServer.RegisterHost(serverVersion, serverName, serverComment.toString());

        // tell everyone what their choices were
        foreach (PlayerInfo p in nvs.players)
        {
            if (p.player != myInfo.player)
            {
                GetComponent <NetworkView>().RPC("StartingGame", p.player, p.cartModel, p.ballModel, p.characterModel);
            }
        }

        // start the game
        BeginGame();
        // set the game to have started
        gameHasBegun      = true;
        nvs.playerHasWon  = false;
        nvs.winningPlayer = "";
        // call the functions that need them
        AddScripts();
    }
    // Use this for initialization
    void Start()
    {
        // setup reference to networkVariables
        nvs = gameObject.GetComponent("networkVariables") as networkVariables;
        myInfo = nvs.myInfo;

        // add us to the player list
        nvs.players.Add(myInfo);

        // get server version
        serverVersion = nvs.serverVersion;	// maybe set the server version to the map name?
        // get server name
        string serverName = nvs.serverName + ": Lobby";
        // serverComment also holds extra info about the server
        serverComment = new ServerComment();
        serverComment.NATmode = nvs.NATmode;
        serverComment.comment = "This is a comment about the server";
        serverComment.level = "level_full";	// only use this one since it's the only one set up atm

        // Use NAT punchthrough if NATmode says to
        Network.InitializeServer(31, 11177, nvs.NATmode!=0);
        Debug.Log(serverComment.toString());
        //MasterServer.updateRate = 5; - not needed anymore since Unity doesn't understand networking
        MasterServer.RegisterHost(serverVersion, serverName, serverComment.toString());

        // get game state
        gameHasBegun = nvs.gameHasBegun;

        // go into the lobby
        gameObject.AddComponent("netLobby");
    }