1. Use Button to control the display and hide of Image or Text
1. Create an Image and Text
2. Create Button
3. Create code
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. Give the code to the thing you want to hide and turn off the display
5. Add click event to Button