目前在我的多人游戏中,我的两个玩家都是在游戏开始时生成的,但我想在等待10秒后生成他们。
因为我想在游戏中提供这种功能,所以我想给玩家一些时间。
Custom Player Spawning
这样我可以更新播放机,然后与网络连接仍然存在两个问题:
-
无法等待10秒,因为callback get会自动调用-OnServerAddPlayer
-
我需要为这些做些什么?
以下是我的网络管理器代码:
public class DodgelsNetworkManager : NetworkManager
{
public override void OnClientConnect (NetworkConnection connection)
{
base.OnClientConnect (connection);
GameHUDController.Instance.UpdateDebugMesssage ("\nOnClientConnect");
Camera.main.SendMessage (GameConstants.ACTIVATE_NETWORK_WAITING_PANEL, true, SendMessageOptions.DontRequireReceiver);
LayerScroller.stopScrolling = true;
// client joined the host
if (connection.connectionId > 0) {
StartCoroutine (AfterDelayHideWaitingDialog ());
}
}
IEnumerator AfterDelayHideWaitingDialog ()
{
GameObject networkPlayerObj = null;
while (networkPlayerObj == null) {
yield return new WaitForSeconds (0.1f);
networkPlayerObj = GameObject.FindGameObjectWithTag (GameConstants.TAG_HUMAN_PLAYER);
}
networkPlayerObj.GetComponent<NetworkPlayerController> ().HidePlayerWaitingDialog ();
}
public override void OnServerAddPlayer (NetworkConnection conn, short playerControllerId)
{
Debug.Log ("-------------OnServerAddPlayer");
GameObject player = Instantiate (playerPrefab, startPositions [conn.connectionId].position, Quaternion.identity);
NetworkServer.AddPlayerForConnection (conn, player, playerControllerId);
}
}
分享你对此的建议。