- Home /
GameObject info
Hello,
I'm working on an inventory for my game and I am adding itmes(game object) in an array, from there I whant to access a javascript to get some variables from there
can anyone tell me how can I do that? I tried everything I could think ...
Inventory.populate(gameObject.Find("Rifle"));
//this is the functin from Inventory.js static function populate(item:GameObject){ items.push(item); }
//
for(var i=0;i<items.length;i++){ var itm:GameObject=items[i];
print(itm.transform.Find("itemDetails"));
}
Thanks
I dont know if i understod your question right, but cant you just use "static" variables?
I think he is. populate function is static, so items must be static too.
Answer by Statement · Mar 30, 2011 at 05:18 PM
Do you mean you want to access a custom script called ItemDetails for every item?
for(var i = 0; i < items.length; i++) {
var item : GameObject = items[i];
var details : ItemDetails = item.GetComponent("ItemDetails");
// use details
}
Answer by user-11002 (google) · Apr 01, 2011 at 05:40 AM
It was with small i, I've changed the name, now I can get the script but can't access any variables from the script, I even made a function that returns my variable...
Anyway thanks a lot for your answer