Version: 2017.3

Network.OnDisconnectedFromServer(NetworkDisconnection)

切换到手册

描述

从服务器断开连接期间在客户端上调用,当连接已经断开后也会在服务器上调用。

在客户端上调用时,连接可能丢失或是从服务器断开。 NetworkDisconnection 枚举会指示 连接是干净的断开还是丢失。 在服务器上调用时,连接已成功断开(调用 Network.Disconnect 之后)。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void OnDisconnectedFromServer(NetworkDisconnection info) { if (Network.isServer) Debug.Log("Local server connection disconnected"); else if (info == NetworkDisconnection.LostConnection) Debug.Log("Lost connection to the server"); else Debug.Log("Successfully diconnected from the server"); } }