Class NetworkLobbyManager | Multiplayer HLAPI | 1.0.8
docs.unity3d.com
    Show / Hide Table of Contents

    Class NetworkLobbyManager

    This is a specialized NetworkManager that includes a networked lobby.

    The lobby has slots that track the joined players, and a maximum player count that is enforced. It requires that the NetworkLobbyPlayer component be on the lobby player objects.

    NetworkLobbyManager is derived from NetworkManager, and so it implements many of the virtual functions provided by the NetworkManager class. To avoid accidentally replacing functionality of the NetworkLobbyManager, there are new virtual functions on the NetworkLobbyManager that begin with "OnLobby". These should be used on classes derived from NetworkLobbyManager instead of the virtual functions on NetworkManager.

    The OnLobby*() functions have empty implementations on the NetworkLobbyManager base class, so the base class functions do not have to be called.

    Inheritance
    Object
    Object
    Component
    Behaviour
    MonoBehaviour
    NetworkManager
    NetworkLobbyManager
    Inherited Members
    NetworkManager.matchName
    NetworkManager.matchSize
    NetworkManager.networkPort
    NetworkManager.serverBindToIP
    NetworkManager.serverBindAddress
    NetworkManager.networkAddress
    NetworkManager.dontDestroyOnLoad
    NetworkManager.runInBackground
    NetworkManager.scriptCRCCheck
    NetworkManager.sendPeerInfo
    NetworkManager.maxDelay
    NetworkManager.logLevel
    NetworkManager.playerPrefab
    NetworkManager.autoCreatePlayer
    NetworkManager.playerSpawnMethod
    NetworkManager.offlineScene
    NetworkManager.onlineScene
    NetworkManager.spawnPrefabs
    NetworkManager.startPositions
    NetworkManager.customConfig
    NetworkManager.connectionConfig
    NetworkManager.globalConfig
    NetworkManager.maxConnections
    NetworkManager.channels
    NetworkManager.secureTunnelEndpoint
    NetworkManager.useWebSockets
    NetworkManager.useSimulator
    NetworkManager.simulatedLatency
    NetworkManager.packetLossPercentage
    NetworkManager.matchHost
    NetworkManager.matchPort
    NetworkManager.clientLoadedScene
    NetworkManager.migrationManager
    NetworkManager.numPlayers
    NetworkManager.defaultTransport
    NetworkManager.activeTransport
    NetworkManager.networkSceneName
    NetworkManager.isNetworkActive
    NetworkManager.client
    NetworkManager.matchInfo
    NetworkManager.matchMaker
    NetworkManager.matches
    NetworkManager.singleton
    NetworkManager.SetupMigrationManager(NetworkMigrationManager)
    NetworkManager.StartServer(ConnectionConfig, Int32)
    NetworkManager.StartServer()
    NetworkManager.StartServer(MatchInfo)
    NetworkManager.UseExternalClient(NetworkClient)
    NetworkManager.StartClient(MatchInfo, ConnectionConfig, Int32)
    NetworkManager.StartClient(MatchInfo)
    NetworkManager.StartClient()
    NetworkManager.StartClient(MatchInfo, ConnectionConfig)
    NetworkManager.StartHost(ConnectionConfig, Int32)
    NetworkManager.StartHost(MatchInfo)
    NetworkManager.StartHost()
    NetworkManager.StopHost()
    NetworkManager.StopServer()
    NetworkManager.StopClient()
    NetworkManager.RegisterStartPosition(Transform)
    NetworkManager.UnRegisterStartPosition(Transform)
    NetworkManager.IsClientConnected()
    NetworkManager.Shutdown()
    NetworkManager.OnServerReady(NetworkConnection)
    NetworkManager.OnServerAddPlayer(NetworkConnection, Int16, NetworkReader)
    NetworkManager.GetStartPosition()
    NetworkManager.OnServerError(NetworkConnection, Int32)
    NetworkManager.OnClientError(NetworkConnection, Int32)
    NetworkManager.OnClientNotReady(NetworkConnection)
    NetworkManager.StartMatchMaker()
    NetworkManager.StopMatchMaker()
    NetworkManager.SetMatchHost(String, Int32, Boolean)
    NetworkManager.OnStopServer()
    NetworkManager.OnMatchCreate(Boolean, String, MatchInfo)
    NetworkManager.OnMatchList(Boolean, String, List<MatchInfoSnapshot>)
    NetworkManager.OnMatchJoined(Boolean, String, MatchInfo)
    NetworkManager.OnDestroyMatch(Boolean, String)
    NetworkManager.OnDropConnection(Boolean, String)
    NetworkManager.OnSetMatchAttributes(Boolean, String)
    MonoBehaviour.IsInvoking()
    MonoBehaviour.CancelInvoke()
    MonoBehaviour.Invoke(String, Single)
    MonoBehaviour.InvokeRepeating(String, Single, Single)
    MonoBehaviour.CancelInvoke(String)
    MonoBehaviour.IsInvoking(String)
    MonoBehaviour.StartCoroutine(String)
    MonoBehaviour.StartCoroutine(String, Object)
    MonoBehaviour.StartCoroutine(IEnumerator)
    MonoBehaviour.StartCoroutine_Auto(IEnumerator)
    MonoBehaviour.StopCoroutine(IEnumerator)
    MonoBehaviour.StopCoroutine(Coroutine)
    MonoBehaviour.StopCoroutine(String)
    MonoBehaviour.StopAllCoroutines()
    MonoBehaviour.print(Object)
    MonoBehaviour.useGUILayout
    MonoBehaviour.runInEditMode
    Behaviour.enabled
    Behaviour.isActiveAndEnabled
    Component.GetComponent(Type)
    Component.GetComponent<T>()
    Component.GetComponent(String)
    Component.GetComponentInChildren(Type, Boolean)
    Component.GetComponentInChildren(Type)
    Component.GetComponentInChildren<T>(Boolean)
    Component.GetComponentInChildren<T>()
    Component.GetComponentsInChildren(Type, Boolean)
    Component.GetComponentsInChildren(Type)
    Component.GetComponentsInChildren<T>(Boolean)
    Component.GetComponentsInChildren<T>(Boolean, List<T>)
    Component.GetComponentsInChildren<T>()
    Component.GetComponentsInChildren<T>(List<T>)
    Component.GetComponentInParent(Type)
    Component.GetComponentInParent<T>()
    Component.GetComponentsInParent(Type, Boolean)
    Component.GetComponentsInParent(Type)
    Component.GetComponentsInParent<T>(Boolean)
    Component.GetComponentsInParent<T>(Boolean, List<T>)
    Component.GetComponentsInParent<T>()
    Component.GetComponents(Type)
    Component.GetComponents(Type, List<Component>)
    Component.GetComponents<T>(List<T>)
    Component.GetComponents<T>()
    Component.CompareTag(String)
    Component.SendMessageUpwards(String, Object, SendMessageOptions)
    Component.SendMessageUpwards(String, Object)
    Component.SendMessageUpwards(String)
    Component.SendMessageUpwards(String, SendMessageOptions)
    Component.SendMessage(String, Object)
    Component.SendMessage(String)
    Component.SendMessage(String, Object, SendMessageOptions)
    Component.SendMessage(String, SendMessageOptions)
    Component.BroadcastMessage(String, Object, SendMessageOptions)
    Component.BroadcastMessage(String, Object)
    Component.BroadcastMessage(String)
    Component.BroadcastMessage(String, SendMessageOptions)
    Component.transform
    Component.gameObject
    Component.tag
    Component.rigidbody
    Component.rigidbody2D
    Component.camera
    Component.light
    Component.animation
    Component.constantForce
    Component.renderer
    Component.audio
    UnityEngine.Component.guiText
    Component.networkView
    UnityEngine.Component.guiElement
    UnityEngine.Component.guiTexture
    Component.collider
    Component.collider2D
    Component.hingeJoint
    Component.particleSystem
    Object.GetInstanceID()
    Object.GetHashCode()
    Object.Equals(Object)
    Object.Instantiate(Object, Vector3, Quaternion)
    Object.Instantiate(Object, Vector3, Quaternion, Transform)
    Object.Instantiate(Object)
    Object.Instantiate(Object, Transform)
    Object.Instantiate(Object, Transform, Boolean)
    Object.Instantiate<T>(T)
    Object.Instantiate<T>(T, Vector3, Quaternion)
    Object.Instantiate<T>(T, Vector3, Quaternion, Transform)
    Object.Instantiate<T>(T, Transform)
    Object.Instantiate<T>(T, Transform, Boolean)
    Object.Destroy(Object, Single)
    Object.Destroy(Object)
    Object.DestroyImmediate(Object, Boolean)
    Object.DestroyImmediate(Object)
    Object.FindObjectsOfType(Type)
    Object.DontDestroyOnLoad(Object)
    Object.DestroyObject(Object, Single)
    Object.DestroyObject(Object)
    Object.FindSceneObjectsOfType(Type)
    Object.FindObjectsOfTypeIncludingAssets(Type)
    Object.FindObjectsOfType<T>()
    Object.FindObjectOfType<T>()
    Object.FindObjectsOfTypeAll(Type)
    Object.FindObjectOfType(Type)
    Object.ToString()
    Object.name
    Object.hideFlags
    Namespace: UnityEngine.Networking
    Syntax
    [AddComponentMenu("Network/NetworkLobbyManager")]
    [Obsolete("The high level API classes are deprecated and will be removed in the future.")]
    public class NetworkLobbyManager : NetworkManager

    Fields

    lobbySlots

    These slots track players that enter the lobby.

    The slotId on players is global to the game - across all players.

    Declaration
    public NetworkLobbyPlayer[] lobbySlots
    Field Value
    Type Description
    NetworkLobbyPlayer[]

    Properties

    gamePlayerPrefab

    This is the prefab of the player to be created in the PlayScene.

    When CheckReadyToBegin starts the game from the lobby, a new player object is created from this prefab, and that object is made the active player object using NetworkServer.ReplacePlayerForConnection.

    Declaration
    public GameObject gamePlayerPrefab { get; set; }
    Property Value
    Type Description
    GameObject

    lobbyPlayerPrefab

    This is the prefab of the player to be created in the LobbyScene.

    This prefab must have a NetworkLobbyPlayer component on it.

    In the lobby scene, this will be the active player object, but in other scenes while the game is running, this will be replaced by a player object created from the GamePlayerPrefab. But once returned to the lobby scene this will again become the active player object.

    This can be used to store user data that persists for the lifetime of the session, such as color choices or weapon choices.

    Declaration
    public NetworkLobbyPlayer lobbyPlayerPrefab { get; set; }
    Property Value
    Type Description
    NetworkLobbyPlayer

    lobbyScene

    The scene to use for the lobby. This is similar to the offlineScene of the NetworkManager.

    Declaration
    public string lobbyScene { get; set; }
    Property Value
    Type Description
    String

    maxPlayers

    The maximum number of players allowed in the game.

    Note that this is the number "players" not clients or connections. There can be multiple players per client.

    Declaration
    public int maxPlayers { get; set; }
    Property Value
    Type Description
    Int32

    maxPlayersPerConnection

    The maximum number of players per connection.

    Calling ClientScene.AddPlayer will fail if this limit is reached.

    Declaration
    public int maxPlayersPerConnection { get; set; }
    Property Value
    Type Description
    Int32

    minPlayers

    The minimum number of players required to be ready for the game to start.

    If this is zero then the game can start with any number of players.

    Declaration
    public int minPlayers { get; set; }
    Property Value
    Type Description
    Int32

    playScene

    The scene to use for the playing the game from the lobby. This is similar to the onlineScene of the NetworkManager.

    Declaration
    public string playScene { get; set; }
    Property Value
    Type Description
    String

    showLobbyGUI

    This flag enables display of the default lobby UI.

    This is rendered using the old GUI system, so is only recommended for testing purposes.

    Declaration
    public bool showLobbyGUI { get; set; }
    Property Value
    Type Description
    Boolean

    Methods

    CheckReadyToBegin()

    CheckReadyToBegin checks all of the players in the lobby to see if their readyToBegin flag is set.

    If all of the players are ready, then the server switches from the LobbyScene to the PlayScene - essentially starting the game. This is called automatically in response to NetworkLobbyPlayer.SendReadyToBeginMessage().

    Declaration
    public void CheckReadyToBegin()

    OnClientConnect(NetworkConnection)

    Declaration
    public override void OnClientConnect(NetworkConnection conn)
    Parameters
    Type Name Description
    NetworkConnection conn
    Overrides
    NetworkManager.OnClientConnect(NetworkConnection)

    OnClientDisconnect(NetworkConnection)

    Declaration
    public override void OnClientDisconnect(NetworkConnection conn)
    Parameters
    Type Name Description
    NetworkConnection conn
    Overrides
    NetworkManager.OnClientDisconnect(NetworkConnection)

    OnClientSceneChanged(NetworkConnection)

    Declaration
    public override void OnClientSceneChanged(NetworkConnection conn)
    Parameters
    Type Name Description
    NetworkConnection conn
    Overrides
    NetworkManager.OnClientSceneChanged(NetworkConnection)

    OnLobbyClientAddPlayerFailed()

    Called on the client when adding a player to the lobby fails.

    This could be because the lobby is full, or the connection is not allowed to have more players.

    Declaration
    public virtual void OnLobbyClientAddPlayerFailed()

    OnLobbyClientConnect(NetworkConnection)

    This is called on the client when it connects to server.

    Declaration
    public virtual void OnLobbyClientConnect(NetworkConnection conn)
    Parameters
    Type Name Description
    NetworkConnection conn

    The connection that connected.

    OnLobbyClientDisconnect(NetworkConnection)

    This is called on the client when disconnected from a server.

    Declaration
    public virtual void OnLobbyClientDisconnect(NetworkConnection conn)
    Parameters
    Type Name Description
    NetworkConnection conn

    The connection that disconnected.

    OnLobbyClientEnter()

    This is a hook to allow custom behaviour when the game client enters the lobby.

    Declaration
    public virtual void OnLobbyClientEnter()

    OnLobbyClientExit()

    This is a hook to allow custom behaviour when the game client exits the lobby.

    Declaration
    public virtual void OnLobbyClientExit()

    OnLobbyClientSceneChanged(NetworkConnection)

    This is called on the client when the client is finished loading a new networked scene.

    Declaration
    public virtual void OnLobbyClientSceneChanged(NetworkConnection conn)
    Parameters
    Type Name Description
    NetworkConnection conn

    The connection that finished loading a new networked scene.

    OnLobbyServerConnect(NetworkConnection)

    This is called on the server when a new client connects to the server.

    Declaration
    public virtual void OnLobbyServerConnect(NetworkConnection conn)
    Parameters
    Type Name Description
    NetworkConnection conn

    The new connection.

    OnLobbyServerCreateGamePlayer(NetworkConnection, Int16)

    This allows customization of the creation of the GamePlayer object on the server.

    By default the gamePlayerPrefab is used to create the game-player, but this function allows that behaviour to be customized. The object returned from the function will be used to replace the lobby-player on the connection.

    Declaration
    public virtual GameObject OnLobbyServerCreateGamePlayer(NetworkConnection conn, short playerControllerId)
    Parameters
    Type Name Description
    NetworkConnection conn

    The connection the player object is for.

    Int16 playerControllerId

    The controllerId of the player on the connnection.

    Returns
    Type Description
    GameObject

    A new GamePlayer object.

    OnLobbyServerCreateLobbyPlayer(NetworkConnection, Int16)

    This allows customization of the creation of the lobby-player object on the server.

    By default the lobbyPlayerPrefab is used to create the lobby-player, but this function allows that behaviour to be customized.

    Declaration
    public virtual GameObject OnLobbyServerCreateLobbyPlayer(NetworkConnection conn, short playerControllerId)
    Parameters
    Type Name Description
    NetworkConnection conn

    The connection the player object is for.

    Int16 playerControllerId

    The controllerId of the player.

    Returns
    Type Description
    GameObject

    The new lobby-player object.

    OnLobbyServerDisconnect(NetworkConnection)

    This is called on the server when a client disconnects.

    Declaration
    public virtual void OnLobbyServerDisconnect(NetworkConnection conn)
    Parameters
    Type Name Description
    NetworkConnection conn

    The connection that disconnected.

    OnLobbyServerPlayerRemoved(NetworkConnection, Int16)

    This is called on the server when a player is removed.

    Declaration
    public virtual void OnLobbyServerPlayerRemoved(NetworkConnection conn, short playerControllerId)
    Parameters
    Type Name Description
    NetworkConnection conn

    The connection the player object is for.

    Int16 playerControllerId

    The controllerId of the player that was removed.

    OnLobbyServerPlayersReady()

    This is called on the server when all the players in the lobby are ready.

    The default implementation of this function uses ServerChangeScene() to switch to the game player scene. By implementing this callback you can customize what happens when all the players in the lobby are ready, such as adding a countdown or a confirmation for a group leader.

    using UnityEngine;
    using UnityEngine.Networking;
    
    public class GuiLobby : NetworkLobbyManager
    {
       float countTimer = 0;
    
       public override void OnLobbyServerPlayersReady()
       {
           countTimer = Time.time + 5;
       }
    
       void Update()
       {
           if (countTimer == 0)
               return;
           if (Time.time > countTimer)
           {
               countTimer = 0;
               ServerChangeScene(playScene);
           }
           else
           {
               Debug.Log("Counting down " + (countTimer - Time.time));
           }
       }
    }
    Declaration
    public virtual void OnLobbyServerPlayersReady()

    OnLobbyServerSceneChanged(String)

    This is called on the server when a networked scene finishes loading.

    Declaration
    public virtual void OnLobbyServerSceneChanged(string sceneName)
    Parameters
    Type Name Description
    String sceneName

    Name of the new scene.

    OnLobbyServerSceneLoadedForPlayer(GameObject, GameObject)

    This is called on the server when it is told that a client has finished switching from the lobby scene to a game player scene.

    When switching from the lobby, the lobby-player is replaced with a game-player object. This callback function gives an opportunity to apply state from the lobby-player to the game-player object.

    Declaration
    public virtual bool OnLobbyServerSceneLoadedForPlayer(GameObject lobbyPlayer, GameObject gamePlayer)
    Parameters
    Type Name Description
    GameObject lobbyPlayer

    The lobby player object.

    GameObject gamePlayer

    The game player object.

    Returns
    Type Description
    Boolean

    False to not allow this player to replace the lobby player.

    OnLobbyStartClient(NetworkClient)

    This is called on the client when a client is started.

    using UnityEngine;
    using UnityEngine.Networking;
    using UnityEngine.UI;
    
    public class Example : NetworkLobbyManager
    {
       //Add this script to your GameObject. Make sure there isn't another NetworkManager in the Scene.
       //Create 2 Buttons (Create>UI>Text) and either:
       //1. assign them in the Inspector of the GameObject this script is attached to or
       //2. remove this part and the listeners and alter the OnClick section on each Button to match up with each function
       //Create a Text GameObject (Create>UI>Text) and attach it to the Status Text field in the Inspector.
    
       public Button m_ClientButton, m_ServerButton;
       bool m_ServerStarted, m_ClientStarted;
    
       void Start()
       {
           showLobbyGUI = true;
           //Call these functions when each Button is clicked
           m_ServerButton.onClick.AddListener(ServerButton);
           m_ClientButton.onClick.AddListener(ClientButton);
       }
    
       //Output a message when your client enters the lobby
       public override void OnLobbyClientEnter()
       {
           m_ClientStarted = true;
           base.OnLobbyClientEnter();
           Debug.Log("Your client has entered the lobby!");
       }
    
       public override void OnLobbyStopClient()
       {
           Debug.Log("Client stopped");
           base.OnLobbyStopClient();
       }
    
       public override void OnLobbyStartServer()
       {
           m_ServerStarted = true;
           base.OnLobbyStartServer();
           Debug.Log("Server Started!");
       }
    
       public override void OnStopServer()
       {
           m_ServerStarted = false;
           base.OnStopServer();
           Debug.Log("Server Stopped!");
       }
    
       //Start the Client when this Button is pressed
       public void ClientButton()
       {
           if (m_ClientStarted == false)
           {
               StartClient();
               m_ClientButton.GetComponentInChildren<Text>().text = "Stop Client";
           }
           else
           {
               StopClient();
               m_ClientButton.GetComponentInChildren<Text>().text = "Start Client";
           }
       }
    
       //Start the Server when this Button is pressed
       public void ServerButton()
       {
           Debug.Log("Server : " + m_ServerStarted);
           if (m_ServerStarted == false)
           {
               StartServer();
               m_ServerButton.GetComponentInChildren<Text>().text = "Stop Server";
           }
           else
           {
               StopServer();
               ServerReturnToLobby();
               m_ServerButton.GetComponentInChildren<Text>().text = "Start Server";
           }
       }
    }
    Declaration
    public virtual void OnLobbyStartClient(NetworkClient lobbyClient)
    Parameters
    Type Name Description
    NetworkClient lobbyClient

    The connection for the lobby.

    OnLobbyStartHost()

    This is called on the host when a host is started.

    //This script shows you how to add extra functionality when the lobby host starts and stops
    //Add this script to your GameObject. Make sure there isn't another NetworkManager in the Scene.
    //Create a Host Button (Create>UI>Text) and assign it in the Inspector of the GameObject this script is attached to
    //Create a Text GameObject (Create>UI>Text) and attach it to the Status Text field in the Inspector.
    
    using UnityEngine;
    using UnityEngine.Networking;
    using UnityEngine.UI;
    
    public class Example : NetworkLobbyManager
    {
       public Button m_HostButton;
       public Text m_StatusText;
       bool m_HostStarted;
    
       void Start()
       {
           //Set the minimum and maximum number of players
           maxPlayers = 6;
           minPlayers = 2;
           maxPlayersPerConnection = 1;
           //Call these functions when each Button is clicked
           m_HostButton.onClick.AddListener(HostButton);
           m_StatusText.text = "Current Scene : " + lobbyScene;
       }
    
       //Output a message when the host joins the lobby
       public override void OnLobbyStartHost()
       {
           //Change the Text to show this message
           m_StatusText.text = "A Host has joined the lobby!";
           m_HostStarted = true;
           //Do the default actions for when the host starts in the lobby
           base.OnLobbyStartHost();
       }
    
       // Output a message to the host when the host stops
       public override void OnLobbyStopHost()
       {
           //Output this message when the host stops
           m_StatusText.text = "A Host has left the lobby!";
           //Do the default actions when the host stops
           base.OnLobbyStopHost();
           m_HostStarted = false;
       }
    
       /// This is where the Buttons are given functionality
       //Start the host when this Button is pressed
       public void HostButton()
       {
           //Check if the host has already started
           if (m_HostStarted == false)
           {
               //Start the host
               StartHost();
               //Change the Button's Text
               m_HostButton.GetComponentInChildren<Text>().text = "Stop Host";
           }
           else
           {
               //If the host has already started, stop the host
               StopHost();
               //Change the Button's Text
               m_HostButton.GetComponentInChildren<Text>().text = "Start Host";
           }
       }
    }
    Declaration
    public virtual void OnLobbyStartHost()

    OnLobbyStartServer()

    This is called on the server when the server is started - including when a host is started.

    using UnityEngine;
    using UnityEngine.Networking;
    using UnityEngine.UI;
    
    public class Example : NetworkLobbyManager
    {
       //Add this script to your GameObject. Make sure there isn't another NetworkManager in the Scene.
       //Create 2 Buttons (Create>UI>Text) and either:
       //1. assign them in the Inspector of the GameObject this script is attached to or
       //2. remove this part and the listeners and alter the OnClick section on each Button to match up with each function
       //Create a Text GameObject (Create>UI>Text) and attach it to the Status Text field in the Inspector.
    
       public Button m_ClientButton, m_ServerButton;
       bool m_ServerStarted, m_ClientStarted;
    
       void Start()
       {
           showLobbyGUI = true;
           //Call these functions when each Button is clicked
           m_ServerButton.onClick.AddListener(ServerButton);
           m_ClientButton.onClick.AddListener(ClientButton);
       }
    
       //Output a message when your client enters the lobby
       public override void OnLobbyClientEnter()
       {
           m_ClientStarted = true;
           base.OnLobbyClientEnter();
           Debug.Log("Your client has entered the lobby!");
       }
    
       public override void OnLobbyStopClient()
       {
           Debug.Log("Client stopped");
           base.OnLobbyStopClient();
       }
    
       public override void OnLobbyStartServer()
       {
           m_ServerStarted = true;
           base.OnLobbyStartServer();
           Debug.Log("Server Started!");
       }
    
       public override void OnStopServer()
       {
           m_ServerStarted = false;
           base.OnStopServer();
           Debug.Log("Server Stopped!");
       }
    
       //Start the Client when this Button is pressed
       public void ClientButton()
       {
           if (m_ClientStarted == false)
           {
               StartClient();
               m_ClientButton.GetComponentInChildren<Text>().text = "Stop Client";
           }
           else
           {
               StopClient();
               m_ClientButton.GetComponentInChildren<Text>().text = "Start Client";
           }
       }
    
       //Start the Server when this Button is pressed
       public void ServerButton()
       {
           Debug.Log("Server : " + m_ServerStarted);
           if (m_ServerStarted == false)
           {
               StartServer();
               m_ServerButton.GetComponentInChildren<Text>().text = "Stop Server";
           }
           else
           {
               StopServer();
               ServerReturnToLobby();
               m_ServerButton.GetComponentInChildren<Text>().text = "Start Server";
           }
       }
    }
    Declaration
    public virtual void OnLobbyStartServer()

    OnLobbyStopClient()

    This is called on the client when the client stops.

    Declaration
    public virtual void OnLobbyStopClient()

    OnLobbyStopHost()

    This is called on the host when the host is stopped.

    Declaration
    public virtual void OnLobbyStopHost()

    OnServerAddPlayer(NetworkConnection, Int16)

    Declaration
    public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
    Parameters
    Type Name Description
    NetworkConnection conn
    Int16 playerControllerId
    Overrides
    NetworkManager.OnServerAddPlayer(NetworkConnection, Int16)

    OnServerConnect(NetworkConnection)

    Declaration
    public override void OnServerConnect(NetworkConnection conn)
    Parameters
    Type Name Description
    NetworkConnection conn
    Overrides
    NetworkManager.OnServerConnect(NetworkConnection)

    OnServerDisconnect(NetworkConnection)

    Declaration
    public override void OnServerDisconnect(NetworkConnection conn)
    Parameters
    Type Name Description
    NetworkConnection conn
    Overrides
    NetworkManager.OnServerDisconnect(NetworkConnection)

    OnServerRemovePlayer(NetworkConnection, PlayerController)

    Declaration
    public override void OnServerRemovePlayer(NetworkConnection conn, PlayerController player)
    Parameters
    Type Name Description
    NetworkConnection conn
    PlayerController player
    Overrides
    NetworkManager.OnServerRemovePlayer(NetworkConnection, PlayerController)

    OnServerSceneChanged(String)

    Declaration
    public override void OnServerSceneChanged(string sceneName)
    Parameters
    Type Name Description
    String sceneName
    Overrides
    NetworkManager.OnServerSceneChanged(String)

    OnStartClient(NetworkClient)

    Declaration
    public override void OnStartClient(NetworkClient lobbyClient)
    Parameters
    Type Name Description
    NetworkClient lobbyClient
    Overrides
    NetworkManager.OnStartClient(NetworkClient)

    OnStartHost()

    Declaration
    public override void OnStartHost()
    Overrides
    NetworkManager.OnStartHost()

    OnStartServer()

    Declaration
    public override void OnStartServer()
    Overrides
    NetworkManager.OnStartServer()

    OnStopClient()

    Declaration
    public override void OnStopClient()
    Overrides
    NetworkManager.OnStopClient()

    OnStopHost()

    Declaration
    public override void OnStopHost()
    Overrides
    NetworkManager.OnStopHost()

    SendReturnToLobby()

    Sends a message to the server to make the game return to the lobby scene.

    Declaration
    public bool SendReturnToLobby()
    Returns
    Type Description
    Boolean

    True if message was sent.

    ServerChangeScene(String)

    Declaration
    public override void ServerChangeScene(string sceneName)
    Parameters
    Type Name Description
    String sceneName
    Overrides
    NetworkManager.ServerChangeScene(String)

    ServerReturnToLobby()

    Calling this causes the server to switch back to the lobby scene.

    Declaration
    public void ServerReturnToLobby()

    TryToAddPlayer()

    This is used on clients to attempt to add a player to the game.

    This may fail if the game is full or the connection cannot have more players.

    Declaration
    public void TryToAddPlayer()
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023