Support => NGUI 3 Support => Topic started by: marcg11 on February 20, 2013, 04:53:45 AM
Title: Programmatically use a UITexture/UISprite
Post by: marcg11 on February 20, 2013, 04:53:45 AM
Hello, I have a Texture2D variable with the texture to add in an empty object. The gameObject is positioned right and now I just want to create an UISprite or UITexture (really don't know which one is the best for my case) and assign somehow my texture to the UISprite/UITexture. How can I acheive that?
public GameObject icon;
void Start()
{
icon = transform.FindChild("icon").gameObject;
icon.AddComponent<UITexture>();// ????
}
publicvoid setSlot(Item _item)
{
Texture2D tex = _item.icon;
print("filling slot");
// ...
}
Title: Re: Programmatically use a UITexture/UISprite
Post by: ArenMook on February 20, 2013, 07:06:47 AM
uiTexture.mainTexture = ...
Title: Re: Programmatically use a UITexture/UISprite
Post by: Nicki on February 20, 2013, 07:16:30 AM
A UISprite gets its texture data from an atlas, while a UITexture gets it from an individual texture.
See the Widget Tool in the unity menus on how to make it. Just make a "Simple Texture" and it will set the basic one up for you.
From code, the mainTexture property is the one you want to mess with.
Title: Re: Programmatically use a UITexture/UISprite
Post by: marcg11 on February 20, 2013, 08:05:55 AM