I'm trying to make my first server/client game on unity, and get stuck with RPC. I'm getting a very strange Null reference exception here:
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]);
}
while the 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;
}
And here are messages:
the new player added from: 169.254.80.80
the player was generated successfully with ID 664652695
player 1 has ip 169.254.80.80 port 50571 with ID 664652695 and info: 1
NullReferenceException ServerOperations.StartTheGame () (at Assets/ServerOperations.cs:66)