The Type Or Namespace UI could not be found - Trying to create a clickable button

Hello! So I am currently trying to create a little weapon shop for a personal project I am working on and I am having a lot of trouble that 45 min of Google could not solve.
The biggest problem so far is that Unity is not registering the ‘UI’ class and I can not figure out why. Here is the current script that I have:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.Events;

public class Master : MonoBehaviour {

    public Button store;
    public UI.Button.ButtonClickedEvent onClick;
    public Transform hands;
    public GameObject gun1;

    // Use this for initialization
    void Start () {
        store = GetComponent<Button>();
        gun1 = GameObject.FindGameObjectWithTag("Weapon1");
        hands = GameObject.FindGameObjectWithTag("Player").transform;
        onClick = Instantiate(gun1, hands.position, hands.rotation);
    }
	
	// Update is called once per frame
	void Update () {
        store.onClick;

    }
}

The exact errors I get are: Severity Code Description Project File Line
Error CS0246 The type or namespace name ‘UI’ could not be found (are you missing a using directive or an assembly reference?) TDS-AYYYY.CSharp C:\Users\Gavin\Documents\TDS-AYYYY\Assets\Scripts\Master.cs 9

(Line 9 is public UI.Button.ButtonClickedEvent onClick;)

And

Severity Code Description Project File Line
Error CS0201 Only assignment, call, increment, decrement, and new object expressions can be used as a statement TDS-AYYYY.CSharp C:\Users\Gavin\Documents\TDS-AYYYY\Assets\Scripts\Master.cs 23

(Line 23 is store.onClick)

I had the same problem and stumbled on this question via google. I fixed it by adding “using UnityEngine.UI” at the top as you did, and then simply removing “UI.” from my declarations. It’s strange… it must be a bug with Unity itself because there’s no reason that using UI.Button as a declaration should fail, I’ve done it before (at least I have with UI.Text).

Here’s my script, it works perfectly now after that tweak:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

[RequireComponent(typeof(Text))]
public class ResourceDisplay : MonoBehaviour {

    enum resEnum {Wood, Iron, Stone, Gold, Food, Population }
    resEnum resSelect;
    private Text txtComp;

	void Start () {
        txtComp = GetComponent<Text>();
	}
	
	void Update () {
	    switch (resSelect)
        {
            case resEnum.Wood:
                txtComp.text = GVars.qWood.ToString();
                break;
            case resEnum.Iron:
                txtComp.text = GVars.qIron.ToString();
                break;
            case resEnum.Stone:
                txtComp.text = GVars.qStone.ToString();
                break;
            case resEnum.Gold:
                txtComp.text = GVars.qGold.ToString();
                break;
            case resEnum.Food:
                txtComp.text = GVars.qFood.ToString();
                break;
            case resEnum.Population:
                txtComp.text = GVars.qPop.ToString();
                break;
        }
	}
}

That worked awesome, thank you.

Wow, this saved my butt too. Just transferred an old project to a new computer, and this was just headscratching. Thank you!