In my game, players shall be able to select units from a menu, which will later be used (placed) in various scenes.
For that, I want to save the unit prefabs in a static array through code.
I then want to access these prefabs, to display some of their variables declared in attached scripts (like name, power and a thumbnail texture) to display on the UI. Later, I want to instantiate them into the scenes.
So far, I fail to save these prefabs to the array.
My code:
//save to array
if (GUI.Button(Rect(h_center-30,v_center-30,50,50), "Ship A")){
arr.Push (Resources.Load("Custom/Prefabs/Ship_Fighter") as GameObject);
}
//display on UI
GUI.Label (Rect (10, 10, 80, 20), arr[i].name.ToString());
From the last line, I get this error:
<i>" 'name' is not a member of 'Object'. "</i>
So, where is my mistake? Did I forget something or declare it wrong, or is my approach here invalid to begin with (i.e, prefabs can't be saved/accessed this way; another type of list would fit this task better).
So in order to get a defined type, i switched to a Generic List, which at least produces no errors in the editor.
However, when i run the scene, and press the button, the gameobject added to the list is empty, resulting in an error when the script tries to access its name.
So apparently, the way i save the prefab to the list isn't working. Where am i going wrong? – Tuxedomask Jan 29 '15 at 11:35