- Home /
Button interactable not working via script
Hi.
A simple function of gameover with some buttons. When the player dies, i'm trying to turn on butons like retry, change character and so on. The weird is the MonoDevelop doesn't recognize the Button component and I can't make then interactable.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class GameOverController : MonoBehaviour {
Button myButton;
void Awake () {
myButton = GameObject.Find ("My Button").GetComponent<Button>();
}
void ButtonOn () {
myButton.interactable = true;
}
}
Whenever I try to call ButtonOn() I got this error: Type Button' does not contain a definition for
interactable' and no extension method interactable' of type
Button' could be found (are you missing a using directive or an assembly reference?).
Else, if I try other common variables, like .enable, I get a NullReference error, as like myButton was null.
Sorry for any mistyping, it's my first post/question ever.
Answer by SkaredCreations · Dec 14, 2014 at 11:38 AM
Are you sure that you haven't a script in your project called Button? It seems so accordingly to this exception.
You did it! I may have created that Button.cs while 4.6 was still beta and forgot its existence. It's working now. Thanks.
Please upvote my answer so your question will be marked as closed ;)
I can't, until my reputation is 15... i'm a nice person, the system should notice it lol
Your answer
Follow this Question
Related Questions
trouble enabling children of a networked player 1 Answer
NullReferenceExeption on gameObject.SetActive 1 Answer
Object reference not set to instance of an object 2 Answers
Custom editor desperation: instance of custom class 1 Answer
How to replace the Button component in the editor with a subclassed version 1 Answer