Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: ENAY on May 17, 2012, 11:47:28 PM

Title: Changing a sprite in code
Post by: ENAY on May 17, 2012, 11:47:28 PM
Ok, stupid question alert. How do I change a sprite into another? In code all I want to do is choose another sprite in the atlas.

Put simply, I want something like this.

MyNGUIMenu.GetComponentsInChildren<UISprite>()[0].image = "image2";


This is for a character select screen, I have my window, multiple faces in the atlas, just need to find that last piece of the puzzle to change the face.
Title: Re: Changing a sprite in code
Post by: dlewis on May 18, 2012, 12:52:28 AM
You will want to change the sprite name.

UISprite mySprite.spriteName = "newSprite";
Title: Re: Changing a sprite in code
Post by: ENAY on May 18, 2012, 01:54:39 AM
I tried spritename earlier and nothing happened. So I tried it again and now it magically works.   >:(
I am sometimes baffled by Unity sometimes.  :-[
Thanks for that dlewis, feels really embarrassing asking such a stupid question but hey, I have no shame. :)
Title: Re: Changing a sprite in code
Post by: dlewis on May 18, 2012, 10:45:06 PM
Thanks for that dlewis, feels really embarrassing asking such a stupid question but hey, I have no shame. :)

Stupid questions are my speciality! :P