Author Topic: UISprite Change sprite  (Read 2873 times)

Malzbier

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 93
    • View Profile
UISprite Change sprite
« on: August 20, 2012, 07:04:10 AM »
Hallo everyone,

I'm trying to exchange the sprite on a UISprite but it does not seem to work.

void Start ()
  1. UISprite uiSpriteCoponent = (UISprite)stagesButtons[i].transform.FindChild("Icon").GetComponent("UISprite");
  2. uiSpriteCoponent.sprite = uiSpriteCoponent.atlas.GetSprite(spriteName);
  3. Debug.Log(uiSpriteCoponent.sprite.name + " VS " + uiSpriteCoponent.spriteName);

gives me this

Quote
Country VS Icon_City

What is the difference between UISprite.sprite.name and UISprite.spriteName ?

Maybe its important but this sprite is instantiated in the Start function too , so its the same frame.


Edit:
Looks like im doing the wrong aproach...  "uiSpriteCoponent.spriteName = spriteName; " is the right way.
« Last Edit: August 20, 2012, 07:11:14 AM by Malzbier »

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: UISprite Change sprite
« Reply #1 on: August 22, 2012, 05:26:54 AM »
Well, I would say that sprite.name return the name of the gameObject whereas spriteName return the name of the sprite.

And yes, you use uiSpriteComponent.spriteName