我试图使我的第一个服务器/客户端游戏统一,并与RPC卡住。我在这里得到一个很奇怪的空引用异常:Unity RPC空引用异常
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具有腹膜ID 664652695和信息169.254.80.80端口50571:1
的NullReferenceException ServerOperations.StartTheGame()(在 资产/ ServerOperations.cs:66)
不要用[标签:团结]关于Unity游戏引擎的问题,标签合一对[ Unity容器](https://msdn.microsoft.com/en-us/library/ff647202.aspx)。 –
哪条线是66线? –
检查你的'networkView'对象是否为空。 – rageit