[英]Changing sprite image to GameObject
如何將精靈圖像轉換或更改為GameObject。 我想使用3D模型而不是圖像。
這是代碼:
public Sprite icon;
if (imageIcon != null)
{
var iconSprite = attribute == null ? null : attribute.icon;
imageIcon.gameObject.SetActive(iconSprite != null);
imageIcon.sprite = iconSprite;
GameObject是組件的容器。 Sprite是適用於組件屬性的對象,例如圖像組件上的sprite屬性。 或者,在您的情況下, 材質中的紋理屬性(需要從子畫面轉換為紋理)。 因此,如果要將精靈圖像應用於游戲對象,只需將精靈應用於附加材質的紋理屬性。
代碼樣例將精靈應用於當前材質
GetComponent().material.mainTexture = Resources.Load<Sprite>("Sprites/MySprite").texture;
在編輯器中,只需將精靈拖放到gameObject上。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.