- Home /
How do I Photon Instantiate a scene object randomly from a list of objects?
Hello world!
I have this script that works with instantiating a scene object in photon during a match after the timer. However I would like it to instantiate a random object from a list of objects after the timer. Not just the same object every time. I want to have options for it to pick from after the timer ends. I know to add [] after the monsterenity prefabs but I don't know how to call it in the PhotonNetwork.InstantiateSceneObject. Any help would be greatly appreciated and thanks. Here is the script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Realtime;
public class MonsterSpawnArea : SpawnArea { public float interval;
 public MonsterEntity monsterPrefab;
 [Range(1, 100)]
 public int amount;
 private bool SpawnComplete = false;
 public void Update()
 {
     if (interval > 0)
     {
         interval -= Time.deltaTime;
     }
     else
     {
         if(SpawnComplete == false)
         {
             SpawnMonsters();
             SpawnComplete = true;
         }
     }
   
 }
 public void SpawnMonsters()
 {
     if (interval <= 0)
     {
         for (int i = 0; i < amount; ++i)
         {
             PhotonNetwork.InstantiateSceneObject(monsterPrefab.name, GetSpawnPosition(), Quaternion.identity, 0, new object[0]);
         }
     }      
 }
}
just a wild guess:
make your moster prefabs an array as you said in your post, then change your instantiation call to monsterPrefab[Random.Range(0,monsterPrefab.Length)].name
Hey! Worked Like a charm thanks a ton!
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                