I’ve got a sprite sheet of weapons and items that I’ve set to “multiple” sprite mode, so I have a bunch of “sub-sprites” from the main sheet. I’ve then created “icon” parameters for, say, a weapon, and dragged the corresponding sub-sprite from the sheet into the inspector slot - now the object has a reference to that sub-sprite.
I want to display this sprite on a GUI when it’s selected (e.g. in an item shop screen), however when I try and use GUI.DrawTexture() on that object’s sub-sprite, instead it draws the entire spritesheet it came from. I then tried using GUI.DrawTextureWithTexCoords(), but this made the sprite seemingly disappear, even though as far as I’m aware, the coordinates were correct. I also tried creating a prefab of the individual sprite and passing it to the UI to display, but this didn’t work either (and seems a bit long-winded to do for every single one when I already have them separated as sub-sprites).
Is there a way to display the single sub-sprite from the main sheet on the GUI?
EDIT: I got DrawTextureWithTexCoords() to work (I forgot to set the last param to true meaning there was no alpha?), but even so, it was a complete pain to go through and find the coords of every single sprite in the main sheet, and displaying it was also annoying.
Ultimately I followed what @lunoland said, but instead of using a prefab with lots of child prefabs for each icon, I gave each item a Sprite attribute, then when the GUI needed to display that item, it just accessed its attached sprite attribute and updated the on-screen item prefab’s sprite to be that. I don’t know if this is the best way to do it, but it works for now and I’ll play around with it some more.