본문 바로가기

진리는어디에

[Unity] Convert Texture2D to Sprite

After making the sprite object into an AssetBundle, I loaded it as a sprite object through AssetBundle, but it failed to load and returned null. In Unity 4.3 version, it is said that when a sprite is built with an AssetBundle, it must be loaded as a texture and converted into a sprite.
So, let's talk a little about how to change a texture to a sprite.

Rect rect = new Rect(0, 0, texture.width, texture.height); sprite.GetComponent<SpriteRenderer>().sprite = Sprite.Create(texture, rect, new Vector2(0.5f, 0.5f));

It's so easy right?
※ Added: Sprites packed using Sprite Packer were loaded normally through asset bundle.

유익한 글이었다면 공감(❤) 버튼 꾹!! 추가 문의 사항은 댓글로!!