hey i am trying to instantiate a random game object randomly every few seconds from one empty game object. i assume that you use a array, however im not sure how to get the prefabs to be represented by the values in the array.
any help would be great what i have so far is this
im aware that this is no where near being functional but any help would be greatly appreciated thanks.
var cubes = Array (cubeGreen, cubeBlue, cubeYellow, cubeMagenta);
var cubeBlue : GameObject;
var cubeYellow : GameObject;
var cubeGreen : GameObject;
var cubeMagenta : GameObject;
function Update()
{
var bin = Random.Range(0, cubes.length);
var clone : GameObject;
clone = Instantiate (gameObject, transform.position, transform.rotation);
}
var cubes : GameObject[];
var spawnInterval = 3.0;
function Start () {
InvokeRepeating("Spawn", .01, spawnInterval);
}
function Spawn () {
Instantiate(cubes[Random.Range(0, cubes.Length)], transform.position, transform.rotation);
}
–Eric
when I try to use this it tells me Unknown identifier: ‘cubes’.
Oh I figured it out but how would I set the spawn pause till gameobject is used? In place of on a timer?
What do you mean by “used”? The InvokeRepeating is what starts the spawning, so you could just move that to whatever function you want to activate it.
Or do you mean you want to have the next cube be created by some event, rather than on a constant interval? In that case, get rid of InvokeRepeating, and just call the Spawn function directly when the event you want happens.