- Home /
Spawning unique prefabs at different transform posititions
I have this script that lets me declare how many prefabs I would like to instantiate within my scene and also define the positions that they would spawn on by using transforms.
public class mystery_box_spawner : MonoBehaviour {
public Transform[] teleport;
public GameObject[] prefeb;
void Start()
{
spawnPrefab ();
}
public void spawnPrefab()
{
int tele_num = Random.Range(0,8);
int prefeb_num = Random.Range(0,3);
Instantiate(prefeb[prefeb_num], teleport[tele_num].position, teleport[tele_num].rotation );
}
}
What I would like to add to this however, would be the ability to have my prefabs spawn only once at a certain position and not have it duplicated and have multiple prefabs spawn at a single position which is currently what happens. Any idea how I can do that? Any help would be much appreciated, thanks so much.
Your answer
Follow this Question
Related Questions
The variable othertransform of Prefab has not been assigned 2 Answers
Problem with GetComponentinChildren and Instantiate 0 Answers
How to follow multiple clones positions of an instantiate prefab having a velocity ? 1 Answer
Parenting GameObjects 1 Answer
How to spawn a 'boss' after all enemies defeated and then kill that 'boss'? 1 Answer