Advertisement
VblacK_Gamer

spawnscript

Apr 12th, 2020
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class SpawnScript : MonoBehaviour
  6. {
  7.  
  8. public Transform[] spawners;
  9. public bool devSpawn = false;
  10. public GameObject obstaclePrefab;
  11. public Vector3 offset;
  12. public const int rangeMin = 2;
  13. public const int rangeMax = 1;
  14.  
  15.  
  16. public void Spawn()
  17. {
  18. int length = spawners.Length;
  19. int toSpawnLength = length - 1;
  20. int spawnsCount = Random.Range(0, toSpawnLength);
  21. //Debug.Log(spawnsCount);
  22. List<int> used = new List<int>();
  23. for (int i = 0; i <= spawnsCount; i++)
  24. {
  25. //Debug.Log("Int: " + i);
  26. int toUse = Random.Range(2, 6);
  27. //Debug.Log("toUse: " + toUse);
  28. while (used.Contains(toUse)){
  29. toUse = Random.Range(2, 6);
  30. }
  31. Transform once = spawners[toUse];
  32. GameObject go = Instantiate(obstaclePrefab, once.position + offset, Quaternion.identity);
  33. used.Add(toUse);
  34. }
  35. }
  36.  
  37. private void Update()
  38. {
  39. if(devSpawn == true)
  40. {
  41. Spawn();
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement