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
}
}
}
↧