- Home /
Can I convert a sprite to a texture2D or use the sprite on a GUI?
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.
Answer by Immanuel-Scholz · Nov 17, 2014 at 11:47 AM
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)
Your answer
Follow this Question
Related Questions
Resize a sprite by giving it more transparent pixels 0 Answers
My sprite from sprite.create looks pixelated. 1 Answer
Slicing sliced sprite via script 0 Answers
Texture2D.Apply() not updating pixels 0 Answers
Texturing custom 2d sprite 0 Answers