///2015/08/04//
//by xbw/
/环境 unity 4.6//
先看一下效果图
不错吧,,,
来代码
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(AudioSource))]
public class MainMenuGUI : MonoBehaviour {
public AudioClip beep;
public GUISkin menuSkin;
public Rect menuArea;
public Rect playButton;
public Rect instructionsButton;
public Rect quitButton;
public Rect playwaysButton;
public Rect instructions;
public Rect HighscoresButton;
public Texture2D img;
Rect menuAreaNormalized;
string menuPage = "main";
// Use this for initialization
void Start () {
menuAreaNormalized =
new Rect(menuArea.x * Screen.width - (menuArea.width * 0.3f), menuArea.y * Screen.height - (menuArea.height * 0.3f), menuArea.width, menuArea.height);
// menuAreaNormalized =
// new Rect(150, 70, Screen.width, Screen.height);
}
void OnGUI()
{
GUIStyle backGround = new GUIStyle();
backGround.normal.background = img;
GUI.Label(new Rect(0, 0, Screen.width, Screen.height), "", backGround);
GUI.skin = menuSkin;
GUI.BeginGroup(menuAreaNormalized);
if (menuPage == "main")
{
if (GUI.Button(new Rect(playButton), "测试模式"))
{
//StartCoroutine("ButtonAction", "second");
//Application.LoadLevel("second");
audio.PlayOneShot(beep);
menuPage = "test";
}
if(GUI.Button(new Rect(HighscoresButton), "酷跑模式"))
{
// audio.PlayOneShot(beep);
StartCoroutine("ButtonAction", "Loading4");
}
if (GUI.Button(new Rect(instructionsButton), "介绍说明"))
{
audio.PlayOneShot(beep);
menuPage = "instructions";
}
//if (GUI.Button(new Rect(playwaysButton), "playways"))
// {
// audio.PlayOneShot(beep);
// menuPage = "playways";
// }
if (GUI.Button(new Rect(quitButton), "退出游戏"))
{
StartCoroutine("ButtonAction", "quit");
}
}
else if(menuPage=="instructions")
{
GUI.Label(new Rect(instructions), "玲珑轮胎测试模式(卡车,跑车,停车入位测试,方向键控制),玲珑酷跑模式(收集四枚玲珑轮胎,空格/触摸,通过碰撞左右移动) ");
if(GUI.Button(new Rect(quitButton),"Back"))
{
audio.PlayOneShot(beep);
menuPage = "main";
}
}
else if(menuPage == "instructionsa")
{
GUI.Label(new Rect(instructions), "未解锁,请选择酷跑模式");
if (GUI.Button(new Rect(quitButton), "Back"))
{
audio.PlayOneShot(beep);
menuPage = "main";
}
}
else if(menuPage == "instructionsb")
{
GUI.Label(new Rect(instructions), "未解锁,请选择酷跑模式");
if (GUI.Button(new Rect(quitButton), "Back"))
{
audio.PlayOneShot(beep);
menuPage = "main";
}
}
else if(menuPage == "instructionsc")
{
GUI.Label(new Rect(instructions), "未解锁,请选择酷跑模式");
if (GUI.Button(new Rect(quitButton), "Back"))
{
audio.PlayOneShot(beep);
menuPage = "main";
}
}
else if(menuPage=="test")
{
//GUI.Label(new Rect(instructions), "方向键控制移动");
if (GUI.Button(new Rect(playButton), "卡车"))
{
audio.PlayOneShot(beep);
//menuPage = "main";
//StartCoroutine("ButtonAction", "Loading");
menuPage = "instructionsa";
}
if (GUI.Button(new Rect(HighscoresButton), "跑车"))
{
audio.PlayOneShot(beep);
//menuPage = "main";
//StartCoroutine("ButtonAction", "Loading2");
menuPage = "instructionsb";
}
if (GUI.Button(new Rect(instructionsButton), "挑战模式"))
{
audio.PlayOneShot(beep);
//menuPage = "main";
//StartCoroutine("ButtonAction", "Loading3");
menuPage = "instructionsc";
}
if (GUI.Button(new Rect(quitButton), "Back"))
{
audio.PlayOneShot(beep);
menuPage = "main";
}
}
GUI.EndGroup();
}
IEnumerator ButtonAction(string levelName)
{
audio.PlayOneShot(beep);
yield return new WaitForSeconds(0.35f);
if(levelName!="quit")
{
Application.LoadLevel(levelName);
}
else
{
Application.Quit();
Debug.Log("Have Quit");
}
}
// Update is called once per frame
void Update () {
}
}
整理了一下素材
链接:http://pan.baidu.com/s/1gdxYZnl 密码:3tu2
一些参数菜单的位置大小自行调整即可