I’m building a spawn generator for items and enemies alike, and have already set up the defined zones with invisible cube gameobjects, using the colliders as triggers to define areas. However, now I’m trying to iterate through each box and place things within it at random. What would be the best way to do this? I’m already collecting the information for each area.
Call instantiateRandomObject(), put the objects and percentage of each one. The chance of each will be percentage/percentageSUM.
var objectPercentage : ObjectPercentage[];
class ObjectPercentage{
var object : GameObject;
var percentage: int=0;
}
function instantiateRandomObject(){
var percentageTotal: int[] = new int[objectPercentage.length];
for(var count : int=0;count<percentageTotal.length;count++){
percentageTotal[count] = objectPercentage[count].percentage;
if(count!=0){
percentageTotal[count] += percentageTotal[count-1];
}
}
var randomNumber: int = Random.Range(1, percentageTotal[percentageTotal.length-1]);
var result : int = -1;
for(var i : int=0;i<percentageTotal.length;i++){
if(randomNumber<=percentageTotal*){*