- Home /
How to instantiate prefabs list in turn photon
Hi, I have tried to instantiate listed prefabs by using photon network, it works but it just instantiates the first listed prefab but what I wanted is to instantiate the listed prefabs by row like when the first player joins it instantiates the first listed prefab, and when the second player joins it instantiates the second listed prefab, I hope that I explained my issue well.
It explains your issue, but to actually help you you have to add some details (code) what you actually and specifically are doing right now.
Please only post the relevant code parts.
this is a code that instantiates a player object but it works only for one object what am trying to say is, is there a way to make a list of player prefabs and instantiates in turn like when it instantiates the first time it chooses the first prefab list when it instantiates the second time it chooses the second prefab in the list.
PhotonNetwork.Instantiate(Player, playerPos, Quaternion.identity, 0);
Answer by Captain_Pineapple · Feb 20 at 11:33 AM
Well sure.
With the given information i assume you have some script that has the task to spawn players when they connect.
Give this script a list of Prefabs:
public GameObject[] PlayerPrefabs;
Don't forget to put some prefabs in there.
Then you have to find a way to track the "playernumber". So when your player connects and instantiates its character you have:
PhotonNetwork.Instantiate(PlayerPrefabs[playernumber], playerPos, Quaternion.identity, 0);
The tracking of the playernumber can be done multiple ways. For example your MasterClient has a counter the increments each time a player joins and then he sends out the number to the newly connected client. Another way would probably to build a system on buffered messages but having the master client send out the playernumber is more reliable imo.