1、新建两个button
2、将脚本挂在Canvas上,并在对应位置拖入button1和button2。
图片如下:
脚本如下:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;//注意这个不能少
//using UnityEditor.Sprites ;
public class showScenes3on : MonoBehaviour {
//public GameObject Gmenue;
public GameObject btnObj ;
public GameObject caidan;
Button btn;
bool isshow=true ;
// Use this for initialization
void Start () {
caidan.SetActive (isshow);
btn = btnObj.GetComponent<Button>();
btn.onClick.AddListener(delegate ()
{
isshow=!isshow;
caidan.SetActive (isshow);
});
}
// Update is called once per frame
void Update () {
}
}