NEW GUI - Button - set interactable via script

I’m trying to recreate the cool down of a button after been used, so I have a timer and all but my problem is that when I try this:

used.GetComponent<Button> ().interactable = true;

it doesn’t recognize the variable/bool interactable and yes I’m using Unity Engine.UI at top, and when I try to type it, those are my options:

36480-screenshot.png

does is called something else or what should it be??

CanisLupus was rigth on the money for some reason I create a script called button and that was where the getComponent was looking for and couldn’t find interactable, delete it and worked, Thanks for the comments and answer!!

Sounds like its a conflict. Button.interactable is the correct member to access. Several users have reported conflicts with some plugins.

Two options to resolve.

  1. Find the conflict and rename the class. Right click on Button in your code editor. Go to “Find Declaration”.

  2. Use the fully qualified name. As in

    GetComponent<UnityEngine.UI.Button>()

using UnityEngine;
using System.Collections;
using UnityEngine.UI; // required when using UI elements in scripts

public class Example : MonoBehaviour {

	public Button startButton;
	public bool playersReady;


	void Update () 
	{
		// checks if the players are ready and if the start button is useable
		if (playersReady == true && startButton.interactable == false) 
		{
			//allows the start button to be used
			startButton.interactable = true;
		}
	}
}
  1. Make sure your have using UnityEngine.UI;
  2. Then set your variable public Button startButton;
  3. Finally call the action startButton.interactable = true;

TIP* NOT button.isInteractble

You should use UnityEngine.UI.Button instead of Button than all problem will be solved.

You can try this:

 using UnityEngine;
 using System.Collections;


 public class Cooldown : MonoBehaviour {

 public Button used;

 // Use this for initialization
 void startCD () 
 {
     StartCoroutine (SkillCD ());
 }
 
 // Update is called once per frame
 IEnumerator SkillCD () 
 {
     yield return new WaitForSeconds(10f);

     used = GameObject.FindGameObjectWithTag ("Used").GetComponent<Button> ();
     used.interactable = true;
     used.gameObject.tag = "Untagged";
 }

I know that this is an old thread but it may help others.

Hi mazket!

Are you trying to acces a Script Component named “Button” or an GameObject?

If Button is an object:

using UnityEngine;
using System.Collections;

public class Cooldown : MonoBehaviour {

	public GameObject used;

	// Use this for initialization
	void startCD () 
	{
		StartCoroutine (SkillCD ());
	}
	
	// Update is called once per frame
	IEnumerator SkillCD () 
	{
		yield return new WaitForSeconds(10f);

		used = GameObject.FindGameObjectWithTag ("Used");
		used.GetComponent<Button> ().interactable = true;
		used.tag = "Untagged";
	}
}

QUESTION 1:
Is “Button” an object or a script name? If it is an object, change the “Button” to the actual script name you are trying to access.

Is “interactable” a private bool? If it is private, it won’t be accessible! Switch to public!

I think you are mixing some components…

Bests, Math!