1、准备工作:
(1) 在HIerarchy上添加待隐藏/显示的物体,名字自取。如:endImage
(2) 在Inspector面板,该物体的名称前取消勾选(隐藏)
(3) 在HIerarchy上添加按钮,名字自取。如:tipsbtn
(4) 在Inspector面板,该按钮的名称前取消勾选(隐藏)
2、新建HideGameObject.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HideGameObject : MonoBehaviour
{
    public GameObject tipsbtn;//按钮
    public GameObject endImage;//图片物体
    // Start is called before the first frame update
    void Start()
    {
        tipsbtn.SetActive(true);//按钮激活状态
        endImage.gameObject.SetActive(false);//图片物体禁用状态
    }
    // Update is called once per frame
    public void DisplayEndImage()//激活图片的方法
    {
        endImage.gameObject.SetActive(true);
    }
}
 
3、回到Unity,赋值
(1) 新建空物体或Canvas,添加 HideGameObject.cs 组件
(2) 在挂载HideGameObject.cs组件的物体上:

(3) 在按钮上:



















