Quantcast
Channel: Latest Questions by haiderInUnity
Viewing all articles
Browse latest Browse all 26

How To avoid random spawn to spawn at previously spawned object position so that they do not overlap

$
0
0
This code randomly spawns objects and then destroy them after some wait. what I want to do is to make sure the random spawned object is not spawned at previously spawned object such as it spawns above it. How may I do that? public IEnumerator Spawn () { yield return new WaitForSeconds (2.0f); counting = true; while (timeLeft > 0 && gameOver==false) { GameObject ball = balls [Random.Range (0, balls.Length)]; Vector3 spawnPosition = new Vector3 ( Random.Range (-maxWidth, maxWidth), Random.Range (-maxHeight, maxHeight), 0.0f); Quaternion spawnRotation = Quaternion.identity; GameObject ballClone = (GameObject) Instantiate (ball, spawnPosition, spawnRotation); StartCoroutine (DestroyAfterWait (ballClone)); yield return new WaitForSeconds (Random.Range (1.0f, 2.0f)); } //yield return new WaitForSeconds (2.0f); GameOver (); }

Viewing all articles
Browse latest Browse all 26

Trending Articles



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