Unity3D聚焦菜单选项

时间:2013-09-19 07:08:01

标签: user-interface focus unity3d

我尝试使用OnGUI元素制作一个简单的游戏菜单。当用户按下“w”和“s”按钮时,所选菜单项看起来不同。(看起来像聚焦)。这是我的代码,我不知道为什么它不起作用。请帮我。 :)谢谢你的时间。

using UnityEngine;

使用System.Collections;

公共课开始:MonoBehaviour {

public int menuCounter = 0;

public string [] menuOptions = {"play","highScores","credits","exit"};

void Update () {

    if(Input.GetKeyDown("s")){
        if(menuCounter == 3){
            menuCounter = -1;
        }
        menuCounter++;
    }

    if(Input.GetKeyDown("w")){
        if(menuCounter == 0){
            menuCounter = 4;
        }
        menuCounter--;
    }

}



void OnGUI(){

    GUI.SetNextControlName("play");
    if(GUI.Button(new Rect(Screen.width/2,Screen.height/2,100,25),"PLAY")){

    }

    GUI.SetNextControlName("highScores");
    if(GUI.Button(new Rect(Screen.width/2,Screen.height/2+30,100,25),"HIGH SCORES")){

    }

    GUI.SetNextControlName("credits");
    if(GUI.Button(new Rect(Screen.width/2,Screen.height/2+60,100,25),"CREDITS")){

    }
    GUI.SetNextControlName("exit");
    if(GUI.Button(new Rect(Screen.width/2,Screen.height/2+90,100,25),"EXIT")){

    }

    GUI.FocusControl(menuOptions[menuCounter]);


}

}

0 个答案:

没有答案