So I’m making a (very bad) clone of Motherload and would like to spawn different types of material, this is how I do it right now:
if(Random.Range(-1000, _generationTimes) >= 1){
if(Random.Range(-2000, _generationTimes) >= 1){
GameObject _cube = (GameObject) Instantiate (Emerald, new Vector3(x, y, 0), Quaternion.identity);
_cube.GetComponent<Element>().Health = 50;
}else{
GameObject _cube = (GameObject) Instantiate (Gold, new Vector3(x, y, 0), Quaternion.identity);
_cube.GetComponent<Element>().Health = 20;
}
}else{
GameObject _cube = (GameObject) Instantiate (Gravel, new Vector3(x, y, 0), Quaternion.identity);
_cube.GetComponent<Element>().Health = 10;
}
But I’d really like to optimize it somehow, I just can’t quite figure how to do it… If I don’t find a better way, this will get very clumsy once I add a few more elements.