我是套接字编程和Unity的新手。 使用这个简单的服务器代码推送演示播放按钮后,我遇到了无限错误
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class PaintServer : MonoBehaviour {
public bool isAtStart = true;
public int port;
// Use this for initialization
void Start () {
Debug.Log("Start");
SetupServer();
}
private void SetupServer()
{
if (NetworkServer.active)
{
Debug.Log("Server is already acitve");
return;
}
NetworkServer.Listen(port);
Debug.Log("Listen Complete");
// system msgs
NetworkServer.RegisterHandler(MsgType.Connect, OnServerConnect);
NetworkServer.RegisterHandler(MsgType.Disconnect, OnServerDisconnect);
NetworkServer.RegisterHandler(MsgType.Error, OnServerError);
DontDestroyOnLoad(gameObject);
}
public void OnServerConnect(NetworkMessage netMsg)
{
Debug.Log("PaintServer received client");
}
public void OnServerDisconnect(NetworkMessage netMsg)
{
Debug.Log("PaintServerlost client");
}
public void OnServerError(NetworkMessage netMsg)
{
Debug.Log("ServerError from Master");
}
public void OnConnect(NetworkMessage netMsg)
{
Debug.Log("player connected!");
}
}
除了上面的代码,我没有脚本。每当我运行程序时,都会出现无限错误消息
主机ID超出范围的标识{0} max id应该大于0且小于 {0} UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()
问题是什么?我该如何解决?请帮帮我。
答案 0 :(得分:0)
我遇到了同样的问题,当Unity失去焦点(点击另一个窗口或桌面)时,控制台中会出现此错误。我通过将我的团结项目设置为“在后台运行”来解决它。
我希望这对你或其他陷入这个问题的人有用。