標籤:
///////////////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 initializationvoid 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 framevoid Update () {}}
整理了一下素材
連結:http://pan.baidu.com/s/1gdxYZnl 密碼:3tu2
一些參數菜單的位置大小自行調整即可
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。
玲瓏杯Unity開發心得——開始菜單GUI製作