I found a previous post wher edynamic names were implemented via Hash Tables. I have the following problem.
I am trying to build a dynamic menu system. My component asks the number of items and the material for each item, then it instaciates an object and assigns the position and material.
Everything went smoooth, I instatitated the items, placed them correctly, etc, but when I wanted to assign a certain material to one of the dynamically created items, I was in trouble!
This is what I did:
var skybox : Material;
var items:int = 4;
var speed:int = 125;
var itemMaterial1 : Material;
var itemMaterial2 : Material;
var itemMaterial3 : Material;
var itemMaterial4 : Material;
var itemMaterial5 : Material;
var itemMaterial6 : Material;
var itemMaterial7 : Material;
var itemMaterial8 : Material;
var itemMaterial9 : Material;
var itemMaterial10 : Material;
private var angInterval:int = 90;
function Awake () {
Camera.main.GetComponent(Skybox).material = skybox;
GameObject.Find("Reflective Water").GetComponent(Skybox).material = skybox;
angInterval = 360/items;
var Menu = GameObject.Find("Menu");
var MenuItem1 = GameObject.Find("MenuItem1");
GameObject.Find("MenuItem1/Plane").renderer.material = itemMaterial1;
for (var i=1;i<items;i++) {
transform.Rotate(0, angInterval, 0);
var NewItem = Instantiate(MenuItem1, Vector3(0,0.5,3), MenuItem1.transform.rotation);
NewItem.name = "MenuItem" + (i+1);
NewItem.transform.parent = transform;
GameObject.Find("MenuItem" + (i+1) + "/Plane").renderer.material = eval("itemMaterial" + (i+1));
}
}
Now I need to assign the newly created item a material that to my javascript knowledge can be assigned like eval(“itemMaterial” + (i+1)). Obviously this does not work.
I even tried a Hash but unity cannot asisgn a material object to a string, or something…
Please help.