Volandpro

Hello!
Is it possible to get sprite of the attachment in code to use it with other Game Objects? Thank you!
Volandpro
  • Bài viết: 3

Harald

You can access the Texture and the UV coordinate region of an Attachment, but you will not get an object of type Sprite directly. A Sprite in Unity is a special structure which is created when Textures are set to mode Sprite, and it holds reference to a Texture and additional information such as the image region, rotation and the like (since they are packed to an Atlas in the background). What you can do is create the Sprite yourself from the retrieved Attachment Texture and Region parameters:
https://docs.unity3d.com/ScriptReference/Sprite.html.

To access Texture and the UV information of the Attachment you can call attachment.GetRegion() to retrieve the AtlasRegion object which holds all information about the atlas texture region.
Hình đại diện của thành viên
Harald

Harri
  • Bài viết: 1951


Quay về Unity