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!
asked Jan 22 '11 at 05:09 PM
You can replace 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
answered Jan 22 '11 at 06:00 PM