1. 用Button控制Image或Text的显示隐藏
1、创建一个Image和Text
2、创建Button
3、创建代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class BtnShowMsg : MonoBehaviour
{
private bool isClick=false; //默认是不显示的
public void Click()
{
if (isClick == false) //创建点击事件,如果当前不显示就让它显示
{
gameObject.SetActive(true);
isClick =true;
}
else //如果当前显示,就让它不显示
{
gameObject.SetActive(false);
isClick = false;
}
}
}
4、把代码给要隐藏的东西并关掉显示
5、给Button加点击事件