hey all, so ive got two empty’s set up , one on the top and one on the bottom of the screen.
I have 4 different shaped objects that are prefabs, what i wish to do is take it in turns every second or so and spawn 1 of the 4 objects either at the top empty of the bottom one, taking it in turns with each spawn location. i have no idea where to begin lol. i have got an outline of what needs to happen
-1 second PASSED
-random pick object out of 4 prefabs
-spawn object at top -CHANGE ACTIVE SPAWN TO BOTTOM-
-1 second PASSED
-random pick object out of 4 prefabs
-spawn object at bottom -CHANGE ACTIVE SPAWN TO TOP-
-REPEAT
thankyou
If you put this in a c# script, define the top and bottom position in the scripts inspector, and the prefabs in the array in the inspector, this will keep spawning a random object randomly, switching from a top position to bottom position
public Transform[] objects;
public Vector3 topPosition, downPosition;
private bool spawning = false, isTop = true;
void Update()
{
//if not spawning, start a new spawn
if(!spawning)
StartCoroutine(Spawn());
}
IEnumerator Spawn()
{
spawning = true;
//select random object out of array
Transform randomObj = objects[Random.Range(0, objects.Length)];
Transform clone;
switch(isTop)
{
case true:
clone = Instantiate(randomObj, topPosition, Quaternion.identity) as Transform;
isTop = false;
break;
case false:
clone = Instantiate(randomObj, downPosition, Quaternion.identity) as Transform;
isTop = true;
break;
}
yield return new WaitForSeconds(1);
spawning = false;
}