i have 3 chests in scene and 3 prefab-items. every chest can carry only one item.
i will randomly instantiate the items to chests and if the chest already has one item, then the script must use next free chest.
i know how to place randomly items, but i don't know how to check the chest and if the chest has one item, how to try next chest?
my first part :
// my prefabs items
var Item01 : GameObject;
var Item02 : GameObject;
var Item03 : GameObject;
// my empty chest positions in scene X, Y, Z
var Chest01 : GameObject; // 0,0,0
var Chest02 : GameObject; // 2,0,0
var Chest03 : GameObject; // 4,0,0
function distributeItem() {
// create array of Items
var RandomChest = new Array();
RandomChest.Add(Chest01);
RandomChest.Add(Chest02);
RandomChest.Add(Chest03);
// create item in random chest
Instantiate(Item01, RandomChest[Random.Range(0,RandomChest.length)].transform.position, transform.rotation);
Instantiate(Item02, RandomChest[Random.Range(0,RandomChest.length)].transform.position, transform.rotation);
Instantiate(Item03, RandomChest[Random.Range(0,RandomChest.length)].transform.position, transform.rotation);
}