Global Game Jam 2021
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.9 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class spawner : MonoBehaviour
  5. {
  6. public GameObject childPrefab;
  7. public int startingAmount = 100;
  8. private Dictionary<string, bool> babyCombos = new Dictionary<string, bool>();
  9. public Collider[] spawnVolumes;
  10. void Start()
  11. {
  12. for (int x = 0; x < startingAmount; x++)
  13. {
  14. SpawnBaby();
  15. }
  16. }
  17. public void SpawnBaby()
  18. {
  19. Vector3 _spawnPoint = RandomPointInBounds(spawnVolumes[Random.Range(0, spawnVolumes.Length)].bounds);
  20. _spawnPoint.y = 1.5f;
  21. var _newChild = Instantiate(childPrefab, _spawnPoint, Quaternion.identity);
  22. _newChild.transform.parent = this.transform;
  23. Randomizer _randomizer = _newChild.GetComponent<Randomizer>();
  24. bool _validChoice = false;
  25. while (!_validChoice)
  26. {
  27. int a, b, c, d, e, f;
  28. a = Random.Range(0, _randomizer.bases.Length);
  29. b = Random.Range(0, _randomizer.hats.Length);
  30. c = Random.Range(0, _randomizer.eyes.Length);
  31. d = Random.Range(0, _randomizer.faces.Length);
  32. e = Random.Range(0, _randomizer.tops.Length);
  33. f = Random.Range(0, _randomizer.bottoms.Length);
  34. string _combination = a.ToString() + b.ToString() + c.ToString() + d.ToString() + e.ToString() + f.ToString();
  35. if (!babyCombos.ContainsKey(_combination))
  36. {
  37. _randomizer.RandomizeParts(a, b, c, d, e, f);
  38. babyCombos.Add(_combination, true);
  39. _validChoice = true;
  40. }
  41. }
  42. }
  43. public static Vector3 RandomPointInBounds(Bounds bounds)
  44. {
  45. return new Vector3(
  46. Random.Range(bounds.min.x, bounds.max.x),
  47. Random.Range(bounds.min.y, bounds.max.y),
  48. Random.Range(bounds.min.z, bounds.max.z)
  49. );
  50. }
  51. }