首先创造画布,图片和button按钮。
在这里插入代码片
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
//引用命名空间;
public class butclick : MonoBehaviour {
//声明变量;
private Button but1;
private Button but2;
private GameObject image1;
private GameObject image2;
// Use this for initialization
//赋值
void Start () {
but1 = transform.Find("Button").GetComponent<Button>();
but2 = transform.Find("Button1").GetComponent<Button>();
image1 = transform.Find("Image").gameObject;
image2 = transform.Find("Image").gameObject;
but1.onClick.AddListener(Dian);
but2.onClick.AddListener(Dian1);
}
// Update is called once per frame
void Update () {
}
public void Dian()
{
image1.SetActive(false);
Debug.Log(111);
}
public void Dian1()
{
image2.SetActive(false);
Debug.Log(222);
}
}
然后挂载到相机上。