|
I have a bunch of cubes that I instantiate with different materials using an ID system. The array of materials is set up like so:
When I create the cubes I do so like this:
Now with another function I am iterating through all of the cubes to get the x, y, and z positions, but I want to also get the texture. If I can figure out the texture from just the gameobject then I want to do that so I don't have to store that information separately. If I do have to store the information some how can i store it with the gameobject itself? Here is an example to show what i mean:
If there isnt some function that lets me get the material name to a string from the gameobject then can I do something like cube.MyVar? Thanks for any help!
(comments are locked)
|
|
You can replace this:
with this:
You don't need the rest of that; the point of arrays is that you don't use individual variables. As for the texture, probably the easiest way is to store the texture number in a component in the prefab. The component can just be a script called "ID" that says
When instantiating, you can do
Then to get the ID later, you can do But without I cant drag references to the materials, right?
Jan 23 '11 at 12:51 AM
user-8533 (google)
Of course you can; just add as many array entries as you need.
Jan 23 '11 at 02:03 AM
Eric5h5
Ah thanks! I see where i was going wrong, have to set the size and pull down the array on the inspector.
Jan 23 '11 at 02:30 AM
user-8533 (google)
(comments are locked)
|
