Hello there I am Trying to Randomly Clone 1 of 5 Gameobjects in a Array. with this code all it seems to do is clone all Gameobjects in the array and not just 1 GameObject.
#pragma strict
var RoomPos : Vector3;
var itemPrefabs : GameObject[];
var testNO : int;
var Obj : GameObject;
function Start(){
RoomPos=this.transform.position;
}
function Update () {
var RNO = Random.Range(1,6);
testNO=RNO;
if (RNO==1){
Obj=itemPrefabs[Random.Range(0, itemPrefabs.Length)];
}
}
function OnTriggerExit(other : Collider){
if(other.tag=="Player"){
SpawnRoom();
}
}
function SpawnRoom (){
//Instantiate(itemPrefabs[Random.Range(0,itemPrefabs.Length)],transform.position, Quaternion.identity);
Instantiate(Obj);
}
Thanks for the the Help Past Present and future.
↧