Quantcast
Channel: Questions in topic: "random spawn"
Viewing all articles
Browse latest Browse all 125

Instantiate a minimum of gameObject (instantiate un nombre minimum de gameObject)

$
0
0
hi everybody, i'm a begginer and i tried to spawn item at random spots. but i need to spawn a minimum of gameObject, like 7. actually, it spawns a random number of gameObject. here is my code to spawn : void Start() { for (int i = 0; i < spawnPosition.Length; i++){ int itemToCreate = Random.Range(0, 3); if (itemToCreate == 0) { itemInScene.Add(Instantiate(diamond, spawnPosition[i].position, Quaternion.identity)); } } scoreCount = 0; level = 1; highScoreText.text = PlayerPrefs.GetInt("BEST").ToString(); } public void MoreDiamond (){ bool checkItemInScene = true; for (int i = 0; i < spawnPosition.Length; i++){ int itemToCreate = Random.Range(0, 10); if (itemToCreate >= 5) { tempDiamond = (GameObject)Instantiate (diamond, spawnPosition [i].position, Quaternion.identity); tempDiamond.transform.name = "Diamond_" + Random.Range (0, 100).ToString("000"); tempDiamond.GetComponent ().DiamondUpgrade (level); itemInScene.Add(tempDiamond); diamondScript.Add(tempDiamond.GetComponent()); } else if (itemToCreate == 1 && checkItemInScene) { itemInScene.Add (Instantiate (itemBall, spawnPosition [i].position, Quaternion.identity)); checkItemInScene = false;//<- instantiate autre chose } } }

Viewing all articles
Browse latest Browse all 125

Trending Articles



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