- Home /
Question by
el-mas-pro-470 · Jan 09, 2019 at 10:20 PM ·
instantiatefpsrandomdeathrandomization
Random death instantiate?
Hello, I need this alone, does anyone know how to instantiate an object at random from a list? in this case, when the enemy dies, it becomes one of several objects on a list, thank you!
void Die ()
{
//there are more objects up but one is assigned
Instantiate (DeathObject, EnemyObject.position, EnemyObject.rotation);
Destroy(EnemyGameObject);
}
}
Comment
Best Answer
Answer by sean244 · Jan 09, 2019 at 10:27 PM
void Die ()
{
var randomIndex = Random.Range(0, listOfDeathObjects.Count);
var death = listOfDeathObjects[randomIndex];
Instantiate(death, EnemyObject.position, EnemyObject.rotation);
Destroy(EnemyGameObject);
}