- Home /
How would I call upon an asset in the projects tab with an array?
I can't seem to figure it out on my own...
Answer by qJake · Jun 14, 2010 at 08:34 PM
You have two options.
Array Referencing and the Inspector
- Create an array with code, say:
public Texture[] myTextures;
- Attach this to a script (C#), and then attach the script to a game object.
- Select the game object in the heirarchy, and look at the Inspector panel. The script should have an array list that you can fill in with whatever assets you want (just drag and drop).
- To change the type of asset in the array, simply change the array type from
Texture[]
to whatever you want.
Using Resources.Load
This method is NOT recommended for all your game assets because it is much less efficient. However, any resources in the folder Resources/ will always be loaded, and can be called by name during scripting. For example, if you had a texture called "Wall" and it was in the Resources folder, you could do:
Texture myWall = Resources.Load("Wall") as Texture;
You could devise some way of loading multiple resources from the Resources folder into an array, though again, the method described above is preferred.
Your answer
Follow this Question
Related Questions
Why does unity reimport the assets every time I open a project? [SOLVED] 1 Answer
how to create multidimensional arrays in javascript 4 Answers
Syntax to initialize 2D (Jagged), built-in array at runtime 1 Answer
I'm having trouble taking a game object from an array and storing it in a variable 1 Answer