Using Spritestate to swap Sprites in Button

Read the documentation but still having a problem getting the following to work. Basically trying to simulate Toggles and ToggleGroup using Buttons. I have ‘Disabled Sprite’ defined properly for offButton1 and offButton2.

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class ToggleButton : MonoBehaviour {
    private bool ButtonOn = false;
    public Button MyButton;
    public Button offButton1;
    public Button offButton2;

    public Sprite pressedSprite;

    public Sprite disabledSprite;

    public SpriteState sprState = new SpriteState();

    public void BeenClicked()
    {
        if(MyButton.image.sprite !=pressedSprite)
        {
            //MyButton.image.color = Color.red;
            MyButton.image.sprite = pressedSprite;

            offButton1.spriteState = sprState.disabledSprite;
            offButton2.spriteState = sprState.disabledSprite;
        }
    }
}

I don’t know what exactly isn’t working for you, because you didn’t mention it. But I did notice that you’re trying to assign a Sprite to a SpriteState in lines 25 and 26. Maybe you meant to do something like this:

//...

offButton1.spriteState.disabledSprite = sprState.disabledSprite;
offButton2.spriteState.disabledSprite = sprState.disabledSprite;

//...

Thanks will make that correction