Change a Button From Script

Hi,
Sorry if it’s in the docs or forum, I couldn’t find anything …
For Button with SpriteSwap - Is there any way to change the Highlighted, Pressed and Disabled sprites attributes from script?
Should I use SpriteState?

It looks like its:

someButton.spriteState.disabledSprite = someSprite;

Its kind of secret but in the editor if you go to Help > Scripting Reference it will open the offline docs that ship with your version of unity in your browser, and in 4.6 those include the API for the UI. The normal online ones won’t include that stuff until uGUI is done with beta I think.

1 Like

Thanks djweinbaum,
The docs doesn’t say much about SpriteState… it works fine.

Sprite newSprite = Resources.Load(“sprites/somesprite”);
SpriteState st = new SpriteState();
st.disabledSprite = newSprite;
st.highlightedSprite = newSprite;
st.pressedSprite = newSprite;
_button.spriteState = st;

1 Like