mazket
1
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:

does is called something else or what should it be??
mazket
3
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!!
Kiwasi
4
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.
-
Find the conflict and rename the class. Right click on Button in your code editor. Go to “Find Declaration”.
-
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;
}
}
}
- Make sure your have using UnityEngine.UI;
- Then set your variable public Button startButton;
- Finally call the action startButton.interactable = true;
TIP* NOT button.isInteractble
jhrhee
5
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!