- Home /
Cant access .interactable
I'm trying to access the .interactable property of my game object, but for some reason I can't. I've made sure that I am using UnityEngine.UI and I believe my code to be correct.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Toggle : MonoBehaviour {
public GameObject myToggle;
void Start () {
LargeBombTgl.GetComponent<Toggle> ().interactable = false;
}
}
When I try to access the .interactable property, no option is available in the monodevelop dropdown menu; the "interactable" text appears to be red. The same outcome is achieved when I change myToggle to type "Toggle" instead of GameObject.
Answer by KdRWaylander · Jun 29, 2015 at 11:37 AM
Hi,
Very first of all, change the name of your script and the name of your classe. Calling it Toggle, like the toggles will only bring you troubles since the name is already taken !
About your problem:
Toggle type instead of GameObject would be better indeed !
public Toggle myToggle;
From there you should be able to call myToggle.interactable
What is LargeBombTgl ? You defined it nowhere so it's normal that Unity won't recognize it !
In the end: If you use public GameObject myToggle;
then you want to use myToggle.GetComponent().interactable = false;
Else, if you use public Toggle myToggle;
you want to use myToggle.interactable = false;
$$anonymous$$y problem was that I named my script Toggle. Thanks for your response!
Calling it Toggle, like the toggles will only bring you troubles since the name is already taken !
Oh ! thank you so much, i had the same problem, but when i changed my buttons from Gameobject to button ins$$anonymous$$d It WOrked ! i can now access the . interactable property !
Your answer
Follow this Question
Related Questions
[4.6] Toggle/Checkbox On/Off 1 Answer
Toggle UI 4.6 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Changing multiple toggle states. 0 Answers