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.

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;