Created
May 9, 2024 10:47
-
-
Save TheCuttlefish/76bb8b4182a1b3aecaf575a085ee20e2 to your computer and use it in GitHub Desktop.
spawn things (once!)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class SpawnObject : MonoBehaviour | |
{ | |
public List<Transform> possiblePositions = new List<Transform>(); | |
public List<GameObject> allThings = new List<GameObject>(); | |
void Start() | |
{ | |
// do something as long as objects in the array exist | |
for (int i = possiblePositions.Count; i > 0; i--) | |
{ | |
int rndObject = Random.Range(0, allThings.Count);// generate a number from 0 to possible objects in the list (that changes) | |
Instantiate(allThings[rndObject], possiblePositions[0].position, Quaternion.identity);// spawn object at the 1st spawn point | |
possiblePositions.RemoveAt(0); // remove spawn position that has been used!! | |
allThings.RemoveAt(rndObject); // remove the spawned object that has been used!! | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment