Author Topic: I am changing the sprite image at runtime but its not changing.  (Read 2665 times)

abhaya.agrawal

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 11
    • View Profile
When i am changing it on mouse click its changing and instantly going back to previous sprite.

this is the code i am using.

 public void Local()
    {
        localButtons.GetComponent<UISprite>().spriteName = "local_inner_shadow";
        cloudButtons.GetComponent<UISprite>().spriteName = "cloud";
    }

i also tried like this
public void Local()
    {
        UISprite sprite1 = localButtons.GetComponent<UISprite>();
        sprite1.spriteName = "local_inner_shadow";
        UISprite sprite2 = cloudButtons.GetComponent<UISprite>();
        sprite2.spriteName = "cloud";
    }

but same problem is there.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: I am changing the sprite image at runtime but its not changing.
« Reply #1 on: April 12, 2015, 04:32:25 PM »
UIButton component will change the sprite. Do you have a button attached?

abhaya.agrawal

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: I am changing the sprite image at runtime but its not changing.
« Reply #2 on: April 14, 2015, 07:16:21 PM »
Yes button is attached.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: I am changing the sprite image at runtime but its not changing.
« Reply #3 on: April 16, 2015, 07:00:27 AM »
So remove it. :P

As I said, button changes the sprite for you. If you want only color to change, use UIButtonColor instead.