public void OnClientDisconnect (Networking.NetworkConnection conn);

参数

conn与服务器的连接。

描述

与服务器断开连接后在客户端上调用。

在客户端与服务器断开连接时在客户端上调用此方法。重载此函数可确定客户端断开连接时发生的情况。

//Attach this script to a GameObject
//Create a Text GameObject(Create>UI>Text) and attach it to the Text field in the Inspector window
//This script changes the Text depending on if a client connects or disconnects to the server

using UnityEngine; using UnityEngine.Networking; using UnityEngine.UI;

public class OnClientConnectExample : NetworkManager { //Assign a Text component in the GameObject's Inspector public Text m_ClientText;

//Detect when a client connects to the Server public override void OnClientConnect(NetworkConnection connection) { //Change the text to show the connection on the client side m_ClientText.text = " " + connection.connectionId + " Connected!"; }

//Detect when a client connects to the Server public override void OnClientDisconnect(NetworkConnection connection) { //Change the text to show the connection loss on the client side m_ClientText.text = "Connection" + connection.connectionId + " Lost!"; } }