玲瓏杯Unity開發心得——開始菜單GUI製作

來源:互聯網
上載者:User

標籤:

///////////////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製作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.