I have a game object that has become the player object when switching scenes. I want each player to have a list of players with some data show up for themselves. To do this I want to instantiate a local game object, but the amount of this object is variable depending on the number of players in the game. My solution:
NetworkManager makes this set of calls when finishing changing scenes:
foreach(NetworkGamePlayer player in GamePlayers)
{
player.CmdSpawnPlayerTabs();
}
Then the player objects each have the following methods:
[Command]
public void CmdSpawnPlayerTabs()
{
TargetSpawnPlayerTabs();
}
[TargetRpc]
public void TargetSpawnPlayerTabs()
{
foreach(NetworkGamePlayer player in Room.GamePlayers)
{
PlayerScrollDataScript listPrefab = Instantiate(playerListPrefab);
//This populates the gameobject with necessary data
listPrefab.SetData(player.RetName(), player.RetIsWinning(), player.RetVP(),
player.RetCurrentResourceCount(), player.RetCurrentDevCardCount(),
player.RetPlayerTurnRoll());
playerList.Add(listPrefab);
listPrefab.gameObject.transform.parent = scrollRect.transform;
listPrefab.gameObject.transform.SetSiblingIndex(player.RetPlayerTurnRoll());
}
}
This seems to still only work for the host and the other players do not get their list populated. I also get an error saying that the player objects don’t have local authority, but the call should be made to the player object that has authority over itself unless I am missing something here.
Let me know if there is some other part of my code that is relevant to this that I should post as well.
Thank you for any help.