Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class SpawnScript : MonoBehaviour
- {
- public Transform[] spawners;
- public bool devSpawn = false;
- public GameObject obstaclePrefab;
- public Vector3 offset;
- public const int rangeMin = 2;
- public const int rangeMax = 1;
- public void Spawn()
- {
- int length = spawners.Length;
- int toSpawnLength = length - 1;
- int spawnsCount = Random.Range(0, toSpawnLength);
- //Debug.Log(spawnsCount);
- List<int> used = new List<int>();
- for (int i = 0; i <= spawnsCount; i++)
- {
- //Debug.Log("Int: " + i);
- int toUse = Random.Range(2, 6);
- //Debug.Log("toUse: " + toUse);
- while (used.Contains(toUse)){
- toUse = Random.Range(2, 6);
- }
- Transform once = spawners[toUse];
- GameObject go = Instantiate(obstaclePrefab, once.position + offset, Quaternion.identity);
- used.Add(toUse);
- }
- }
- private void Update()
- {
- if(devSpawn == true)
- {
- Spawn();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement