我試圖使我的第一個服務器/客戶端遊戲統一,並與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