c# - 制作一个弹出面板,询问我是否确定要在 Unity 中购买特定商品
问题描述
就像在标题中一样,当我按下购买特定商品的按钮时,我想制作一个面板,并询问我是否确定要购买该商品以及是否按“是”购买。会有很多项目,我不想为每个项目制作一个单独的面板。
解决方案
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);
};
}
}
把它放在一个空的项目上,然后做一个预制件。然后当你想使用它时实例化你的预制件
推荐阅读
- arrays - 我在 GCC 编译器中遇到分段错误
- c++ - #include 导致的编译错误
- single-sign-on - 通过 HTTP 重定向绑定到 ADFS 的 SAML 注销请求以请求者的身份获得响应而不是成功 - 从浏览器发起的请求
- firebase - 我正在尝试使用flutter和firebase制作一个杂货应用程序,一切正常,但是当我按下复选框时,它会检查所有这些
- sql - 从 BigQuery 到数据洞察的日期格式
- laravel - 如何在 Laravel 8 中将订单发票号黑色传递给查看
- xamarin - 如何在 Xamarin 中调整和压缩图像文件的大小
- javascript - 使用动态图像实现自动完成
- java - JavaFX KeyEvent.consume() 无法停止事件传播
- javascript - 从 Web 扩展的后台脚本中访问 about:addons 的内容