So I’m doing a first person thing where you toss trash around the woods and eventually get attacked by a bear…anyway, i want to randomly create trash. I’ve modeled the different pieces of trash (5 for now, i might add more).
I have the code to create objects on a mouse click attached to the first person controller…
var newObject : Transform;
function Update () {
if (Input.GetButtonDown("Fire1")) {
Instantiate(newObject, transform.position, transform.rotation);
}
what do i need to add to make it create random objects?
var variousTrashPrefabs : GameObject[]; //assign all kinds of trashy objects here via the inspector
function RandomTrash()
{
var randomIndex : int = Random.Range(0,variousTrashPrefabs.length);
Instantiate(variousTrashPrefabs[randomIndex], transform.position, transform.rotation);
}