Skip to main content
This is C# code, not the deprecated language UnityScript
Source Link
DMGregory
  • 140.8k
  • 23
  • 257
  • 401

So i'mI'm trying to change the function of a button by a clickable method in unityUnity. I'm using a get componentGetComponent to acces deaccess the button component of the game object and then putassign the clickable function. 

But when iI get this error:

GetComponent requires that the requested component 'Button' derives from MonoBehaviour or Component or is an interface

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UIElements;
using Button = UnityEngine.UIElements.Button;

public class Button_System : MonoBehaviour
{
    public GameObject Button01;
    public GameObject Image01;

    public void Start()
    { 
        Button01.GetComponent<Button>().clickable = new Clickable(Example);
    }

    public void Example()
    {
        Image01.SetActive(false);
    }

So i'm trying to change the function of a button by a clickable method in unity. I'm using a get component to acces de button component of the game object and then put the clickable function. But when i get this error:

GetComponent requires that the requested component 'Button' derives from MonoBehaviour or Component or is an interface

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UIElements;
using Button = UnityEngine.UIElements.Button;

public class Button_System : MonoBehaviour
{
    public GameObject Button01;
    public GameObject Image01;

    public void Start()
    { 
        Button01.GetComponent<Button>().clickable = new Clickable(Example);
    }

    public void Example()
    {
        Image01.SetActive(false);
    }

So I'm trying to change the function of a button by a clickable method in Unity. I'm using a GetComponent to access the button component of the game object and then assign the clickable function. 

But I get this error:

GetComponent requires that the requested component 'Button' derives from MonoBehaviour or Component or is an interface

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UIElements;
using Button = UnityEngine.UIElements.Button;

public class Button_System : MonoBehaviour
{
    public GameObject Button01;
    public GameObject Image01;

    public void Start()
    { 
        Button01.GetComponent<Button>().clickable = new Clickable(Example);
    }

    public void Example()
    {
        Image01.SetActive(false);
    }
Source Link

Assign clickable function to UI Button Unity

So i'm trying to change the function of a button by a clickable method in unity. I'm using a get component to acces de button component of the game object and then put the clickable function. But when i get this error:

GetComponent requires that the requested component 'Button' derives from MonoBehaviour or Component or is an interface

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UIElements;
using Button = UnityEngine.UIElements.Button;

public class Button_System : MonoBehaviour
{
    public GameObject Button01;
    public GameObject Image01;

    public void Start()
    { 
        Button01.GetComponent<Button>().clickable = new Clickable(Example);
    }

    public void Example()
    {
        Image01.SetActive(false);
    }