I am trying to assign different sprites into an array called sprites. I want each value of the array to hold a different spritesheet. Right now i am getting this error i dont understand why… :
Cannot implicitly convert type `UnityEngine.Sprite[]' to `UnityEngine.Sprite'
In my public declaration i have:
public static int MAIN_SPRITE = 1;
public Sprite[] sprites;
further down in my void Start () i have:
void Start () {
sprites = new Sprite[32];
}
and then i am trying to assign the spritesheet in my init() method like this:
sprites[MAIN_SPRITE] = Resources.LoadAll<Sprite>("mainImg");
where mainImg is the name of my sprite sheet.
What am i doing wrong ?
(The error appears for my last command where i set the array)
-Thanks
Resources.LoadAll(“mainImg”);
is already returning an array. Just assign it to the array directly without the indexer
Hi Sandbird,
You are getting this because sprites[MAIN_SPRITRE] refers to a single sprite and not all the array, use this instead:
sprites = Resources.LoadAll(“mainImg”) as Sprite;
I’ve never used Resources.LoadAll but I think it returns an array, so you can not set a single element to it’s returned array. I believe also that it returns an array of objects, so you will need to cast this object array to a sprite array using “as Sprite”
I hope that helps 
If you have any questions, leave a comment and let me know if it works 
Beau C
You don’t have to trick anything. You can assign your sprites with values and call that up at specific times. If you want to start with a specific sprite you put it in the [0] and call that in the void Start. And then you can change it in a method afterwards.