您的位置:首页 > 其它

No Lobby for LobbyPlayer

2015-12-11 18:58 211 查看
控制台打印错误如下:

No Lobby for LobbyPlayer

UnityEngine.Networking.NetworkLobbyPlayer:OnStartClient()

莫名其妙的问题,还以为哪里设置错了,google一下,http://forum.unity3d.com/threads/networkmanager-singleton-is-null.355587/#post-2339014

因为我继承了NetworkLobbyManager类,并且重写了Awake函数,所以父类的Awake不执行了,NetworkLobbyManager单例的实例化则为空,追踪到源代码可以看到:

public override void OnStartClient ()
{
NetworkLobbyManager networkLobbyManager = NetworkManager.singleton as NetworkLobbyManager;
if (networkLobbyManager)
{
networkLobbyManager.lobbySlots [(int)this.m_Slot] = this;
this.m_ReadyToBegin = false;
this.OnClientEnterLobby ();
}
else
{
Debug.LogError ("No Lobby for LobbyPlayer");
}
}


因此把Awake里需要初始化的代码移到Start方法里去就行了,像这样:

static public LobbyManager s_Singleton;
void Start()
{
if (s_Singleton != null && s_Singleton != this)
{
Destroy(gameObject);
return;
}

DontDestroyOnLoad(gameObject);
s_Singleton = this;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: