- Home /
How to Randomly Add a Gameobject from a set of GameObjects to another set of Gameobjects
Hi I'm trying to randomly add gameobjects to a gameobject set
So this is what I have and it works, but I need it to randomise; public GameObject[] NPCEasy; public GameObject[] NPCNormal; public GameObject[] NPCHard; public GameObject[] NPCBoss;
public GameObject[] NpcTypes;
waves [0].NpcTypes = NPCEasy;
waves [1].NpcTypes = NPCEasy;
waves [2].NpcTypes = NPCEasy;
waves [3].NpcTypes = NPCNormal;
waves [4].NpcTypes = NPCNormal;
waves [5].NpcTypes = NPCNormal;
waves [6].NpcTypes = NPCHard;
waves [7].NpcTypes = NPCHard;
waves [8].NpcTypes = NPCHard;
waves [9].NpcTypes = NPCBoss;
Answer by Tourist · Nov 28, 2016 at 09:00 AM
Create an array of all available configurations (NPCEasy, NPCNormal, NPCHard and NPCBoss).
Then for each wave wanted, define weights for each configuration. This will alllow you to have better management over the randomness. For instance, wave1 could have 6, 3, 1, 0 for each configuration below. Sum all weights for a wave and use Random.Range(0, sumOfallWeights). Depending on the result of random call, instantiate the proper wave.
Your answer
Follow this Question
Related Questions
drag and drop mathgame 2 Answers
Assign a random material to objects 1 Answer
How to Spawn multiple game object one by one in random order 1 Answer
spawn muzzle flash with random rotation? 2 Answers
I am trying to Randomize my Answers? 1 Answer