- Home /
Accessing textures through code.
Hey guys,
I'm trying to figure out how I could access textures through code. I know I could just declare var tex1 : Texture2D; and assign it through the inspector but say I have a hundred textures I need to access in my script.
I'm looking for something similar to this:
var textures : Array = new Array ();
function Start (
for (i=0;i<100;i++) {
textures.Add(find_texture_i_in_my_project_folder);
}
}
Say all these textures are in a folder called Textures, which is inside my Project folder. The order in which I add them is unimportant. Is there a way to do this? Because I often find myself dragging and dropping a LOT of textures to scripts, and it gets tedious ;).
Answer by by0log1c · Apr 29, 2011 at 03:44 PM
Something like this?
var textureNames:String[] = new String[x];
var textures:Texture2D[] = new Texture2D[x];
function Start(){
for(i=0;i<textureNames.length;i++){ textures[i] = Resources.Load(textureNames[i]);
}
That would load the texture named 'textureNames[i]' from the folder Resources, located in the root of your project. Replace 'x' with the actual number of textures. Refer to:
Your answer
Follow this Question
Related Questions
max fbx material import problem 3 Answers
how do you assign a texture atlas pict to a texture 2 Answers
How to make unity, auto assign shader and texture correctly? 2 Answers
Can't assign a texture from WWW to Image.material.maintexture 1 Answer
load all the textures of a folder into an array through code 1 Answer