- Home /
How do I access the button component of a button in the new gui system.
I'm using unity 4.6 and I would like to access the button component of a button so I can set it's interactable bool in it when the game reaches certain conditions but there does not seem to be a Button class that I can access so I cannot get a reference to the button. Does anyone know how to access the button component?
Answer by Louis Watson · Sep 20, 2014 at 09:42 PM
interactable is a member of UI.Selectable attach the following to your button to have debug display its state:
using UnityEngine;
using UnityEngine.UI;
public class interactTest : MonoBehaviour {
Selectable button;
void OnEnable () {
button = gameObject.GetComponent<Selectable>();
Debug.Log(button.interactable.ToString());
}
}
Answer by orb · Sep 20, 2014 at 09:22 PM
You need to import UnityEngine.UI in addition to UnityEngine to see the Button class in auto-completion.
Your answer
Follow this Question
Related Questions
How can a button be highlighted but not trigger on click event when submit button is pressed? 0 Answers
Unity 4.6 GUI weird toggle+button interaction? 2 Answers
IPointerClickHandler error 2 Answers
Move gameobject to button in new 4.6? 0 Answers
How to access SourceImage component of a button in new GUI 4.6 1 Answer