首页 > 解决方案 > 制作一个弹出面板,询问我是否确定要在 Unity 中购买特定商品

问题描述

就像在标题中一样,当我按下购买特定商品的按钮时,我想制作一个面板,并询问我是否确定要购买该商品以及是否按“是”购买。会有很多项目,我不想为每个项目制作一个单独的面板。

标签: c#visual-studiouser-interfaceunity3deditor

解决方案


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Deny : MonoBehaviour {
    public string mess = "Are you sure?";
Rect body;

public vois Start(){
body= new Rect(Screen.width / 2 - 150, Screen.height / 2 - 32, 300, 64)
}

    private void OnGUI()
    {
        GUI.depth = -3;
        GUI.Box(body, mess);
        GUI.Button(new Rect(body.x+5,body.y+body.height-50, 110,46 ),"Yes"){
//player clicked yes handle it
 //after your work : Destroy(this.gameObject);
};
  GUI.Button(new Rect((body.x+body.width)-115,body.y+body.height-50, 110,46 
),"no"){
//player clicked no handle it
//after your work : Destroy(this.gameObject);
};

    }
}

把它放在一个空的项目上,然后做一个预制件。然后当你想使用它时实例化你的预制件


推荐阅读