Author Topic: Change the texture of UItexture  (Read 3390 times)

brian661

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 12
    • View Profile
Change the texture of UItexture
« on: April 02, 2014, 08:46:44 AM »
I would like to change the texture dynamically by using something like

  1. GameObject loadedPrefab = Resources.Load("item") as GameObject;
  2. loadedPrefab.transform.GetComponent<UITexture>().mainTexture="";
  3.  


where item is a Texture widget prefab, 
My image have been add to the atlas, or inside the Asset/Resources/image folder,
how can i set it to the mainTexture?

brian661

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: Change the texture of UItexture
« Reply #1 on: April 02, 2014, 08:57:26 AM »
I find the ans
  1. loadedPrefab.transform.GetComponent<UITexture>().mainTexture=Resources.Load("your texture location") as Texture;
  2.