Legacy Documentation: Version 2018.2 (Go to current version)
LanguageEnglish
  • C#

NetworkLobbyManager.OnLobbyStartClient

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public void OnLobbyStartClient(Networking.NetworkClient lobbyClient);

Parameters

lobbyClientThe connection for the lobby.

Description

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>Buttons) 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"; } } }

Did you find this page useful? Please give it a rating: