I have been looking around but am unable to find an answer to this question, can I use a sprite on OnGUI in C# or can I convert a sprite to a Texture2D or do I have to make this manually with photoshop or something like that?
Thanks,
Jan Julius.
EDIT: This question is different from my previous question.
can I use a sprite on OnGUI in C# or can I convert a sprite to a Texture2D
You can access the sprite atlas texture with Sprite.texture and its UV-rectangle with Sprite.textureRect and then use GUI.DrawTextureWithTexCoords… IF you don’t use tight sprite packing.
In tightly packed atlasses you simply do not have a bounding rectangle around the sprite. You could maybe somehow get the mesh of the sprite and draw it using Graphics.DrawMesh, but… that’s beyond my quick explanation capability :). You may ask in the forums and hope to attract some dev explaining these options ;).
If you don’t mind the overhead, you can keep the sprite packing policy to “Default Policy” to have them non-tight packed… (Windows/Sprite Packer)