Answer the question
In order to leave comments, you need to log in
How to spawn a unity2d object?
How to spawn in such a way that 1 of 3 objects would be selected and spawned after 1 - 2 seconds?
Answer the question
In order to leave comments, you need to log in
public GameObject obj1;
public GameObject obj2;
public GameObject obj3;
public void Start(){
StartCoroutine(Spawner());
}
IEnumerator spawner(){
while(true){
yield return new WaitForSecond(2f);
int obj = Random.Range(1,3);
switch(obj){
case 1:
Instantiate(obj1, new Vector3(i * 2.0F, 0, 0), Quaternion.identity);//свои координаты лепите
break;
case 2:
Instantiate(obj2, new Vector3(i * 2.0F, 0, 0), Quaternion.identity);//свои координаты лепите
break;
case 3:
Instantiate(obj3, new Vector3(i * 2.0F, 0, 0), Quaternion.identity);//свои координаты лепите
break;
}
}
Coroutine for a random time between 1-2 seconds. Instantiate on "spawn" or object pool if for the sake of optimization.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question