Unity3D之Ugui 制作弹框

创建一个UI控件。

这里通过按钮的点击取控制弹框的显示或者隐藏。给按钮Button绑定一个脚本。

将Panel初始化设置为隐藏。就可以实现了。

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class basetest : MonoBehaviour {

    public GameObject panel;
    private bool isclick = false; 
    // Use this for initialization
    void Start () {
    
    }
    
    // Update is called once per frame
    void Update () {
    
    }
    void OnMouseOver() { 
        if(Input.GetMouseButtonDown(0)){ //左键点击
            Debug.LogError("你点击了NPC");
            //playRenwu();
        }
        
    }

    void playRenwu(bool isnotclick) {
        Debug.LogError("开始NPC任务");
        panel.gameObject.SetActive(isnotclick);
    }

    public  void Onclickbutton()
    {
        if (isclick == false)
        {
            Debug.LogError("你点击了按钮");
            isclick = true;
            playRenwu(true);         
        }
        else {
            isclick = false;
            playRenwu(false);
        }
        
   
    }
}
原文地址:https://www.cnblogs.com/sunxun/p/5802237.html