using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class spawner : MonoBehaviour
|
|
{
|
|
public GameObject childPrefab;
|
|
|
|
public int startingAmount = 100;
|
|
|
|
private Dictionary<string, bool> babyCombos = new Dictionary<string, bool>();
|
|
|
|
public Collider[] spawnVolumes;
|
|
|
|
void Start()
|
|
{
|
|
for (int x = 0; x < startingAmount; x++)
|
|
{
|
|
SpawnBaby();
|
|
}
|
|
}
|
|
|
|
public void SpawnBaby()
|
|
{
|
|
Vector3 _spawnPoint = RandomPointInBounds(spawnVolumes[Random.Range(0, spawnVolumes.Length)].bounds);
|
|
|
|
_spawnPoint.y = 2.5f;
|
|
|
|
var _newChild = Instantiate(childPrefab, _spawnPoint, Quaternion.identity);
|
|
_newChild.transform.parent = this.transform;
|
|
|
|
Randomizer _randomizer = _newChild.GetComponent<Randomizer>();
|
|
|
|
bool _validChoice = false;
|
|
while (!_validChoice)
|
|
{
|
|
int a, b, c, d, e, f;
|
|
|
|
a = Random.Range(0, _randomizer.bases.Length);
|
|
b = Random.Range(0, _randomizer.hats.Length);
|
|
c = Random.Range(0, _randomizer.eyes.Length);
|
|
d = Random.Range(0, _randomizer.faces.Length);
|
|
e = Random.Range(0, _randomizer.tops.Length);
|
|
f = Random.Range(0, _randomizer.bottoms.Length);
|
|
|
|
string _combination = a.ToString() + b.ToString() + c.ToString() + d.ToString() + e.ToString() + f.ToString();
|
|
|
|
if (!babyCombos.ContainsKey(_combination))
|
|
{
|
|
_randomizer.RandomizeParts(a, b, c, d, e, f);
|
|
babyCombos.Add(_combination, true);
|
|
_validChoice = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static Vector3 RandomPointInBounds(Bounds bounds)
|
|
{
|
|
return new Vector3(
|
|
Random.Range(bounds.min.x, bounds.max.x),
|
|
Random.Range(bounds.min.y, bounds.max.y),
|
|
Random.Range(bounds.min.z, bounds.max.z)
|
|
);
|
|
}
|
|
}
|