如何在游戏开始后停止新的玩家连接。在游戏开始前我有最多4个玩家连接限制和10秒的计时器。如果3/2球员连接并且比赛开始,则第4个玩家将为空(意味着游戏以3或2个玩家开始)。比赛开始后第4名球员不应该连接。他/她需要等待下一轮。
游戏IP地址为localhost
,端口为7777
。所以第四名玩家将无法连接到此地址。
这是我的网络连接代码。
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
using UnityEngine.UI;
public class Network_Manager_Custom : NetworkManager {
private Animator anim;
//[SerializeField]private GameObject btnDisconnect;
public void StartupHost()
{
setPort ();
NetworkManager.singleton.StartHost ();
//Debug.Log ("I am calling from startupHost.!");
}
public void JoinGame()
{
setIPAddress ();
setPort ();
NetworkManager.singleton.StartClient ();
}
public void setIPAddress()
{
string IPAddress = GameObject.Find ("InputFieldIPAddress").transform.FindChild("Text").GetComponent<Text>().text;
NetworkManager.singleton.networkAddress = IPAddress;
Debug.Log ("IPAddress : "+ IPAddress);
}
void setPort()
{
NetworkManager.singleton.networkPort = 7777;
}
void OnLevelWasLoaded(int level)
{
if (level == 0) {
SetupMenuScreenButtons ();
} else {
SetupOtherSceneButtons ();
}
}
void SetupMenuScreenButtons()
{
GameObject.Find ("btnStartHost").GetComponent<Button>().onClick.RemoveAllListeners();
GameObject.Find ("btnStartHost").GetComponent<Button> ().onClick.AddListener (StartupHost);
GameObject.Find ("btnJoinGame").GetComponent<Button>().onClick.RemoveAllListeners();
GameObject.Find ("btnJoinGame").GetComponent<Button> ().onClick.AddListener (JoinGame);
}
void SetupOtherSceneButtons()
{
//btnDisconnect = GameObject.Find ("btnDisconnect");
//if (btnDisconnect != null) {
GameObject.Find ("btnDisconnect").GetComponent<Button> ().onClick.RemoveAllListeners ();
GameObject.Find ("btnDisconnect").GetComponent<Button> ().onClick.AddListener (NetworkManager.singleton.StopHost);
//} else {
// Debug.Log("btnDisconnect not available.!");
//}
}
}
任何人都可以帮助我。?
我该怎么做?如何阻止玩家连接当前正在运行的游戏。?