Instatiate help
Ok for some reason I cant seem to wrap my head around this, perhaps im tied. I have a list of gameobjects that I instatiate to a random list of spawn points around the world. It works exactly like i hoped but my problem is it only spawns the amount that is in the lists count . I would like it to spawn 100 randomly selected objects from the item list to randomly selected spawns. So 1 spawn might get 2 items another might get 6 another might get 9. for some reason I can figure this out. I'm using photon so perhaps it might have something to do with Photon.Instatiate("only letting me use a string",pos,pos, byte);
The loot spawns randomly to the spawns but only the same amount as the count of the list
Any ideas would be great..
this is the instatiate code
void OnJoinedRoom(){
if (PhotonNetwork.isMasterClient) {
for (int i = 0; i < loot.Count; i++) {
if (Random.value * 100 < loot [i].spawnChance) {
PhotonNetwork.Instantiate (loot[i].lootobject.name, lootSpawns [Random.Range (0, lootSpawns.Count)].transform.position, Quaternion.identity, 0);
}
}
}
Answer by ChristianSimon · Sep 14, 2017 at 07:52 AM
Hi,
you have to implement a loop that runs 100 times. Within this loop you have to randomly select an object from your list (temporary save its name because you need it for Network Instantiation) and a spawn point (temporary save this either). Then you call PhotonNetwork.Instantiate with the stored name, the stored position and both left parameters (Rotation and Group) like you already do.
Your answer
Follow this Question
Related Questions
Spawn Gameobject over all Clients and server not working 0 Answers
Photon Unity Network ERROR 2 Answers
How to fix "Creating a peer when 2 players meet" ? (in Photon) 0 Answers
Players won't spawn with Photon Unity Network 1 Answer
Photon Networking - How I can see if the player is the host? - C# 1 Answer