Button Sprite Swap ?


Is there a way how to control the sprite states of a button when it is clicked ? I mean i have 10 buttons in total and if one of these buttons is clicked i want to set its state to pressed and others to disabled. How can i do this ? Is there a way to assign these sprites to each state of Sprite Swap Transition of the buttons and then decide which one of them should be in a pressed state and others in disabled state through script ?

Also, I don’t want to assign all the sprites manually to my script because there are 10 buttons and each of them has 3 different states so in total it would be 30 sprites to assign in the inspector and I want to avoid that. It would be better if these sprites could be assigned directly to the transition mode of the buttons and then in my script i would set the sprite state of each button depending on the condition that i want to have.

Here is the code that i am using to set the button of the selected item to pressed state:

public Button[] shopItemButtons;

void Start()
		for (int i = 0; i < shopItemButtons.Length; i++)
			shopItemButtons[selectedItem].spriteState = shopItemButtons[selectedItem].spriteState.pressedSprite;

If anyone has an idea please share it.
Thank you,

Sure. Have the event system handle it. Unity’s built in event system can tell which element its not currently hovering over then if the buttons that is not being hovered over by the mouse can be set to disabled. Hence swapping the sprite. If you set the sprite on the button in inspector.