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.

53 lines
1.5 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. void Start()
  10. {
  11. for (int x = 0; x < startingAmount; x++)
  12. {
  13. SpawnBaby();
  14. }
  15. }
  16. public void SpawnBaby()
  17. {
  18. float _x = Random.Range(-45, 45);
  19. float _z = Random.Range(-35, 35);
  20. var _newChild = Instantiate(childPrefab, new Vector3(_x, 1.5f, _z), Quaternion.identity);
  21. _newChild.transform.parent = this.transform;
  22. Randomizer _randomizer = _newChild.GetComponent<Randomizer>();
  23. bool _validChoice = false;
  24. while (!_validChoice)
  25. {
  26. int a, b, c, d, e, f;
  27. a = Random.Range(0, _randomizer.bases.Length);
  28. b = Random.Range(0, _randomizer.hats.Length);
  29. c = Random.Range(0, _randomizer.eyes.Length);
  30. d = Random.Range(0, _randomizer.faces.Length);
  31. e = Random.Range(0, _randomizer.tops.Length);
  32. f = Random.Range(0, _randomizer.bottoms.Length);
  33. string _combination = a.ToString() + b.ToString() + c.ToString() + d.ToString() + e.ToString() + f.ToString();
  34. if (!babyCombos.ContainsKey(_combination))
  35. {
  36. _randomizer.RandomizeParts(a, b, c, d, e, f);
  37. babyCombos.Add(_combination, true);
  38. _validChoice = true;
  39. }
  40. }
  41. }
  42. }