Version: 5.6
public static void CloseConnection (NetworkPlayer target, bool sendDisconnectionNotification);

説明

他のシステムへの接続を解除します

target は、どのシステムに対する接続を解除するか指定します。 クライアント上で実行する場合、解除する接続の選択肢はサーバーへの接続のみになります。サーバー上であれば、ターゲットしたプレイヤーが弾かれます。 sendDisconnectionNotification は、相手方に対して送る通知の有効・無効を設定します。無効の場合、通知なしで接続が切断され、有効の場合は接続切断の通知がリモートパーティに対して送信されてから接続が切断されます。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void OnGUI() { if (GUILayout.Button("Disconnect from server")) if (Network.connections.Length == 1) { Debug.Log("Disconnecting: " + Network.connections[0].ipAddress + ":" + Network.connections[0].port); Network.CloseConnection(Network.connections[0], true); } else if (Network.connections.Length == 0) Debug.Log("No one is connected"); else if (Network.connections.Length > 1) Debug.Log("Too many connections. Are we running a server?"); if (GUILayout.Button("Disconnect first player")) if (Network.connections.Length > 0) { Debug.Log("Disconnecting: " + Network.connections[0].ipAddress + ":" + Network.connections[0].port); Network.CloseConnection(Network.connections[0], true); } } }