I have an image GameObject that changes Sprite depending on the inventory page. So when a user clicks an item, it changes the image to match that. I’m trying to store all of the possible sprites into a Sprite. it makes it much easier for coding reasons. However, I’m having a lot of trouble.
I originally started with a public Sprite, and tried to set it up with public Sprite variables. But for some reason it was always returning null unless i set it up as static. My Sprite is now static, as well as the Sprite variables i want to put into the array. However, i can’t click and drag the sprites into their public variables anymore, through the inspector, because they are now static, and I don’t know how to set sprites any other way.
Now I’m somewhat stuck. I even tried (shamefully) to make a bunch of public Sprites, and then tried to set the static Sprites by the non-static ones, - like public static image0 = otherImage; but apparently non-static sprites won’t be accepted into a static sprite variable.
I’ve tried the Resources.LoadAll method, but it’s confusing, and i can’t figure out how to SEE let alone set the images up in the right order into my Sprite.
Any help would be appreciated.
EDIT:
Here is how i’ve been trying to display the Sprite:
int imageNumber = weaponList [page, 20];
spriteToUse = imageList [imageNumber];
and here is how i’ve been trying to set it (as non-static):
public Sprite image0;
public Sprite image1;
public Sprite image2;
public Sprite[] imageList = new Sprite[] {
image0,
image1,
image2,
...
};
If I create a static Sprite and static Sprites to fill it, it will recognise it, and not get a null exception when i try to get it. However, I don’t know how to properly set static Sprites into a Sprite array. (I normally just use the inspector to drop and drag sprites onto their public variable placeholders.)