Hi,
I am making a multiplayer game in which players are spawned in on level 1, they are supposed to finish a task, and when done they need to wait for all players to finish the task before everyone moves on to level 2.
For this I thought I’d save all instantiated players into a list when they are spawned, something like this:
[SerializeField] GameObject playerObject;
public List<GameObject> allPlayersInGame = new List<GameObject>();
private void SpawnPlayer()
{
GameObject _player = PhotonNetwork.Instantiate(playerObject.name, startPos.position, startRot.rotation);
allPlayersInGame.Add(_player);
}
However, when I print the length of the list in the update loop of my game controller it is always 1. I tried to print PhotonNetwork.PlayerList.Length which gives me 1 when I add first player and then correctly 2 when 2nd player joins.
What is the most simple way I can store all players (player objects) that joins the game and then access each of thems script later on?