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!!
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;
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.
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!