Toggle Button State Programmatically

I am using the new UI and attempting to toggle a button state to ‘On’ or ‘Off’. I have experimented with both Event.current.SetSelectedGameObject and in using a Toggle component to switch out versions of the same button. Using the Event engine produces no discernible results, and the Toggle node seems to reveal the second Button without offering it’s interactivity.

Is there a simple way to set a button to ‘Pressed’ and leave it down? I can understand how the Event engine might overwrite changes on subsequent frames, but I don’t understand why there are no controls of this sort exposed through the UI.

Its not done yet. this sort of component is on our todo list.

Is there a way that I can use the current tools to achieve what I am after? Ideally, I would like to Toggle two buttons with different graphics, but I could accept a scripted approach. Perhaps adding another button event script?

I’m not sure if it is a bug, but the Toggle UI item didn’t seem to be responding to the swap-sprite animation at it’s root.

using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace ca.HenrySoftware.Utomata
{
    public class PlayButton : MonoBehaviour, IPointerClickHandler
    {
        [SerializeField] private Sprite _play;
        [SerializeField] private Sprite _pause;
        private Image _image;
        private bool _playing;
        private void Awake()
        {
            _image = GetComponent<Image>();
        }
        public void OnPointerClick(PointerEventData e)
        {
            if (_playing = !_playing)
                _image.sprite = _pause;
            else
                _image.sprite = _play;
        }
    }
}

did you add toggle component with add component?

try creating a toggle control from the create menu instead of adding the toggle component from the add component menu because a full toggle control consists of multiple components and game objects

Thanks for the code snippet. The toggle was added using the create menu, but I was using a beta version of Unity 5, and I am going to rebuild the project in 4.6.1 and see if it isn’t an issue in the implementation.

Thanks again for the help,
r