I'm trying to make a rock that after you break it, it will spawn a random item from the minerals array. How can I pick a random item from the minerals array and then instantiate it?
var rockHealth : int = 50;
var rock : GameObject;
var speed : int = 8;
var rb : Rigidbody;
var copper : Transform;
var gold : Transform;
var minerals : Transform[];
minerals.push(copper);
minerals.push(gold);
function DeductPoints(hitpoints : int) {
rockHealth -= hitpoints;
}
function Update() {
if(rockHealth <= 0) {
DestroyRock();
}
}
function DestroyRock() {
Destroy(rock);
var position : Vector3 = Vector3(Random.Range(-1.0, 1.0), 0, Random.Range(-1.0,1.0));
Instantiate("random mineral would go here", rock.transform.position + Vector3(0,0,0) + position, Quaternion.identity);
}