A bit complicated instantiate question

So i have 3 meteors, they are all disabled. I want to make it so that with a script i can call a function, that will spawn a copy of the disabled meteor, undisable it, let it fall across the screen, then destroy the gameobject. So that at any time, i can call the function and have a meteor fall down. I also want to randomize which one falls down so that constantly a random meteor falls down every few seconds. So it creates the effect that you are flying through a whole lot of meteors, but its infinite.

Seems like you already have it figured out. You’re going to want to create 3 variables and store your meteors there. You will then want to “Instantiate” using “Random.Range” to randomize between your 3 meteor variables. You can then start an “InvokeRepeating” loop to “Instantiate” every whatever timespan you choose. The words in “” are the keywords you want to check out. I am willing to help you out with this and help you write and explain anything you need for as long as you need me to. However, I am not willing to write the code for you as that won’t really help you at all.

#pragma strict
var m1 : GameObject;
var m2 : GameObject;
var m3 : GameObject;

InvokeRepeating("SpawnMeteors", 2, 2);

function SpawnMeteors()
	var meteors : Array = Array(m1,m2,m3);
	var position : Vector3 = Vector3(Random.Range(-10.0, 10.0), 0, 0);
	Instantiate(meteors[Random.Range(0, meteors.length)], position, m1.transform.rotation);

This is tested an confirmed to work. If however you run into any problems let me know.

like Nick4 said, you can define a list of spawn places, if you create an array and hold the spawn places in there you can randomly choose different meteor prefabs (assuming u want some uniqueness) and then randomly spawn the amount, and random range location of them.

For example (this wont be 100% accurate nor complete but an outline)

private bool CheckForMeteorPrefabs() {
		if (meteorPrefab.Length > 0)
			return true;
			return false;
	private bool CheckForSpawnPoints() {
		if (spawnPoints.Length > 0)
			return true;
			return false;
	//generate a list of available spawnpoints that do not have any meteors childed to it
	private GameObject[] AvailableSpawnPoints() {
		List<GameObject> gos = new List<GameObject>();
		for(int cnt = 0; cnt < spawnPoints.Length; cnt++) {
			if (spawnPoints[cnt].transform.childCount == 0) {
				Debug.Log("**meteor spawn point available**");