創建一個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); } } }