Ich habe die folgende einfache Klasse Networkbehaviour erstreckt. Ich muss auf eine Verbindung zum Server warten, um eine [Command] -Funktion aufzurufen.OnConnectedToServer nicht genannt werden [UNET]
Any Lage UNET oder Multiplayer-Experten, mir zu sagen, was ich falsch mache?
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
public class KeepClientConnected : NetworkBehaviour {
public int pingInterval = 30;
// Use this for initialization
void Awake() {
DontDestroyOnLoad(transform.gameObject);
}
void Start(){
}
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");
}
private void OnConnectedToServer()
{
Debug.Log("0 ASSERT OnConnectedToServer");
StartCoroutine(myCoRoutine());
}
[Command]
void Cmd_KeepConnection()
{
Debug.Log("2 ASSERT calling KeepConnection on Server");
}
IEnumerator myCoRoutine()
{
while (true)
{
Cmd_KeepConnection();
Debug.Log("1 ASSERT calling KeepConnection on Server");
yield return new WaitForSeconds(2);
}
}
}