public Texture tex_help;//帮助菜单贴图
public Texture tex_option;//设置菜单贴图
public Texture tex_x;//游戏第二章界面贴图
private int gameState;//当前游戏状态
}
绘制游戏主界面,配合If语句判定所绘制的按钮是否被点击,使用OnGUI()函数实现按钮的绘制,计算屏幕当前宽度和高度,设定按钮大小,通过换算使得按钮居中纵向排布,并且实现相关按钮的点击功能。
具体实现代码如下:
//绘制主菜单界面
void RenderMainMenu()
{
GUI.skin = menui;//设置界面皮肤
GUI.DrawTexture(new Rect(0,0,Screen.width,Screen.height),tex_BG);//绘制游戏背景图
//绘制开始游戏按钮
if (GUI.Button(new Rect(Screen.width/2 - 80,250,160,40),"","btn_start"))
{
gameState = STATE_STARTGAME;//跳转状态
}
//绘制游戏设置按钮
if (GUI.Button(new Rect(Screen.width/2 - 80,350,160,40),"","btn_option"))
{
gameState = STATE_OPTION;//跳转状态
}
//绘制游戏帮助按钮
if (GUI.Button(new Rect(Screen.width/2 - 80,450,160,40),"","btn_help"))
{
gameState = STATE_HELP;//跳转状态
}
//绘制游戏退出按钮
if (GUI.Button(new Rect(Screen.width/2 - 80,550,160,40),"","btn_exit"))
{
Application.Quit();//退出游戏 基于Unity引擎的三维游戏“火线突围”设计(5):http://www.751com.cn/yishu/lunwen_13245.html