Making an array for Texture2D??

hey guys for some reason I am having an issue with a pretty simple task.

how do I declare an array for 2D textures

I have tried:

    var xxQWE : Texture2D[3];
    var arrxxSpells : Texture2D[] = new Texture2D[10]

and neither are working.


If you want to populate the array in the Inspector, use this:

var textures: Texture2D[];

This will show a field named Textures in the Inspector: you must define its size and drag the textures to it in the Inspector. You can also pre-define the size in the script, like this:

var textures: Texture2D[] = new Texture2D[5];

In this case, the Textures field will have a pre-defined number of items, and you can populate it in Inspector like above.

On the other hand, if you want to populate the array at runtime via script, be aware that the declarations above create an array of Texture2D references , not the textures themselves: you must assign Texture2D objects to the array elements before modifying them - for instance:

var textures: Texture2D[]; // declare the array
var size: int = 5;

function Start(){
  textures = new Texture2D; // create the array
  for (var i = 0; i < size; i++){ // populate it with 200x100 empty textures:
    textures *= new Texture2D(200, 100);*


From Unity 5.4b-5 you can use Texture2DArray