【发布时间】:2015-06-02 12:59:32
【问题描述】:
我正在尝试在 unity 上制作我的第一个服务器/客户端游戏,但被 RPC 卡住了。我在这里遇到了一个非常奇怪的 Null 引用异常:
for (int b = 1; b <= Network.connections.Length; b++)
{
playerList[b] = genPlayer(Network.connections[b-1]);
Debug.Log(
"player " + b +
" has ip " + Network.connections[b - 1].ipAddress +
" port " + Network.connections[b - 1].port +
" with ID " + playerList[b].ID +
" and info: " + playerList[b].info.guid);
networkView.RPC("GetID", playerList[b].info, playerList[b].ID, b);
ResendHand(playerList[b]);
}
而 genPlayer:
public player genPlayer(NetworkPlayer plr)
{
Debug.Log("the new player added from: " + plr.ipAddress);
player pl = new player();
pl.ID = getID();//just a random int
pl.card1 = getCard(pl.ID); //random card
pl.card2 = getCard(pl.ID);
pl.card3 = getCard(pl.ID);
pl.card4 = getCard(pl.ID);
pl.card5 = getCard(pl.ID);
pl.score = 0;
pl.vote = 0;
pl.info = plr;
Debug.Log("the player was generated successfully with " + "ID " + pl.ID);
return pl;
}
这里是消息:
新加入的玩家来自:169.254.80.80
播放器已成功生成,ID 为 664652695
玩家 1 拥有 ip 169.254.80.80 端口 50571,ID 为 664652695,信息:1
NullReferenceException ServerOperations.StartTheGame () (在 资产/ServerOperations.cs:66)
【问题讨论】:
-
不要使用unity 来回答有关 Unity 游戏引擎的问题,Unity 的标签是针对 Microsoft 的 Unity Container。
-
第 66 行是哪一行?
-
检查您的
networkView对象是否为空。 -
第 66 行:networkView.RPC("GetID", playerList[b].info, playerList[b].ID, b);
-
这一点也不奇怪。您显然没有在代码上使用调试器。
标签: c# unity3d nullreferenceexception rpc