Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Spawning different random objects at the same position?

$
0
0
I've been trying to spawn two objects at random. But the random function generates only one random value at runtime, and so only one of the object gets spawned. I want both of them to spawn at random intervals. Help! Thank You! public float SpawnTime; public GameObject Object1; public GameObject Object2; private int i; // Use this for initialization void Start () { i = Random.Range (1, 6); StartSpawn (); } void Update () { } public void StartSpawn() { if (i > 3) { InvokeRepeating ("SpawnObject1", 0.2f, SpawnTime); } else InvokeRepeating ("SpawnObject2", 0.2f, SpawnTime); } void SpawnObject1(){ Instantiate(Object1, new Vector3(transform.position.x,0,0), Quaternion.identity); } void SpawnObject2(){ Instantiate(Object2, new Vector3(transform.position.x,0,0), Quaternion.identity); } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>