Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by pabloromocl · Jul 17, 2013 at 02:06 PM · gui

GUI.FocusControl working partially

Hi,

I'm working now in a pause screen where you have the following options:

  • Continue Playing

  • Adjust Volume -> Triggers a new menu screen to adjust the volume

  • Exit -> Triggers a new menu screen to confirm the selection

First Menu

First Menu - Moving throught options

There if i move with the keyboard or the joystick the GUIFocusControl is working fine, changing the colors of the buttons when is active or onHover.

The problem comes with the "Adjust Volume Menu", the keyboard is changing betweeen options, but it doesnt' change the colors of the button unless i use the mouse onHover:

Volume Menu - No active buttons or bar

Volume Menu - Mouse on Hover on the bar

Volume Menu - Mouse on Hover on the button

Also, this is working just fine in the confirm menu:

Confirm menu - Just keyboard

The worst part of all, is that i'm using almost the same script in another game and is working just fine. I really don't know what is happening.

I hope you can help me out here.

I leave the script right here:

 #pragma strict
 
 var MainMenu:String;
 var skin:GUISkin;
  
 private var savedTimeScale:float;
 
 private var screenWidth:int;
 private var screenHeight:int;
 
 var pauseButton:String;
  
 var statColor:Color = Color.yellow;
  
 enum Page {
     None,Main,Volume, Confirm
 }
 
 private var selectedIndex:int = 0;
 private var mainMenu:String[] = ["Continuar", "Volumen", "Salir"];
 private var volumeMenu:String[] = ["Volumen", "Volver"];
 private var confirmMenu:String[] = ["Confirmar", "Volver"];
 
 var menuClip:AudioClip;
 var menuExplanationClip:AudioClip;
 var defaultOptionClip:AudioClip;
 var volumeClip:AudioClip;
 var exitClip:AudioClip;
 var volumeExplanationClip:AudioClip;
 var backClip:AudioClip;
 var continueClip:AudioClip;
 var beepClip:AudioClip;
 
 var confirmExplanationClip: AudioClip;
 var confirmClip: AudioClip;
 var backmainClip: AudioClip;
 
 var playerAudio:PlayAtPlayer;
     
 private var mainMenuAudio:AudioClip[];
 private var volumeMenuAudio:AudioClip[];
 private var confirmMenuAudio:AudioClip[];
 
 private var currentPage:Page;
 
 var continue_skin : GUISkin;
 var adjustVolume_skin : GUISkin;
 var volumeMenu_skin : GUISkin;
 var volumeBar_skin : GUISkin;
 var exit_skin : GUISkin;
 var confirm_skin : GUISkin;
 var cancel_skin : GUISkin;
 
 function Start() {
     playerAudio = GameObject.FindGameObjectWithTag("PlayerAudio").GetComponent(PlayAtPlayer);
     mainMenuAudio = [ continueClip, volumeClip, exitClip ];
     volumeMenuAudio = [ volumeExplanationClip, backClip ];
     confirmMenuAudio = [confirmExplanationClip, confirmClip, backClip ];
     screenWidth = Screen.width;
     screenHeight = Screen.height;
     Time.timeScale = 1.0;
 }
  
 function LateUpdate () {
 
     if (Input.GetButtonDown(pauseButton) || XInput.GetButtonDown(pauseButton))  {
         switch (currentPage) {
             case Page.None: PauseGame(); break;
             case Page.Main: UnPauseGame(); break;
             default: playerAudio.PlayWithPriority(menuClip, 5); currentPage = Page.Main; break;
         }
     }
     var currentMenu:String[];
     
     switch(currentPage) {
         case Page.Main: currentMenu = mainMenu; break;
         case Page.Volume: currentMenu = volumeMenu; break;
         case Page.Confirm: currentMenu = confirmMenu; break;
         default: return;
     }
     
     if (Input.GetButtonDown("Down") || XInput.GetButtonDown("Down")) {
         menuSelection(currentMenu, "down");
     }
  
     if (Input.GetButtonDown("Up") || XInput.GetButtonDown("Up")) {
         menuSelection(currentMenu, "up");
     }
     
     if (Input.GetButtonDown("Enter") || XInput.GetButtonDown("A")) {
         handleSelection("Enter");
     }
     
     if (Input.GetButtonDown("Left") || XInput.GetButtonDown("Left")) {
         handleSelection("Left");
     }
     
     if (Input.GetButtonDown("Right") || XInput.GetButtonDown("Right")) {
         handleSelection("Right");
     }
             
 }
 
 function menuSelection (currentMenu:Array, direction:String) {
     
     var audioClips:AudioClip[];
     
     switch(currentPage) {
         case Page.Main: audioClips = mainMenuAudio; break;
         case Page.Volume: audioClips = volumeMenuAudio; break;
         case Page.Confirm: audioClips = confirmMenuAudio; break;
         default: return;
     }    
     if (direction == "up") {
         if (selectedIndex == 0) {
             selectedIndex = currentMenu.length - 1;
         } else {
             selectedIndex -= 1;
         }
     }
     
     if (direction == "down") {
         if (selectedIndex == currentMenu.length - 1) {
             selectedIndex = 0;
         } else {
             selectedIndex += 1;
         }
     }
     
     playerAudio.PlayWithPriority(audioClips[selectedIndex], 5);
     
     
 }
 
 function handleSelection(command:String) {
     
     switch(currentPage) {
         case Page.Main:
             if (command == "Enter") {
                 if (selectedIndex == 0) {
                     UnPauseGame();
                     break;
                 } else if (selectedIndex == 1) {
                     selectedIndex = 0;
                     currentPage = Page.Volume;
                     playerAudio.PlayWithPriority(volumeExplanationClip, 5);
                     break;
                 } else if (selectedIndex == 2) {
                     selectedIndex = 0;
                     currentPage = Page.Confirm;
                     playerAudio.PlayWithPriority(confirmExplanationClip, 5);
                     break;
                 }
             }
             break;
         case Page.Volume:
             if (selectedIndex == 0) {
                 if (command == "Left") {
                     AudioListener.volume = Mathf.Max(0, AudioListener.volume - 0.1);
                     playerAudio.PlayWithPriority(beepClip, 5);
                 }
                 
                 if (command == "Right") {
                     AudioListener.volume = Mathf.Min(1.0, AudioListener.volume + 0.1);
                     playerAudio.PlayWithPriority(beepClip, 5);
                 }
             }
             
             if (command == "Enter") {
                 if (selectedIndex == 0) {
                     selectedIndex = 1;
                     playerAudio.PlayWithPriority(beepClip, 5);
                 } else {
                     selectedIndex = 0;
                     currentPage = Page.Main;
                     playerAudio.PlayWithPriority(menuClip, 5);
                 }
             }
             break;
         case Page.Confirm:
             if (command == "Enter") {
                 if (selectedIndex == 0) {
                     UnPauseGame();
                     Application.LoadLevel(MainMenu);
                     break;
                 } else {
                     selectedIndex = 0;
                     currentPage = Page.Main;
                     playerAudio.PlayWithPriority(menuClip, 5);
                 }
             }
             break;
         default: break;
             
     }
 
 }
  
 function OnGUI () {
     if (skin != null) {
         GUI.skin = skin;
     }
     
     screenWidth = Screen.width;
     screenHeight = Screen.height;
 
     if (IsGamePaused()) {
         //GUI.color = statColor;
         switch (currentPage) {
             case Page.Main: PauseMenu(); break;
             case Page.Volume: VolumeMenu(); break;
             case Page.Confirm: ConfirmationMenu(); break;
         }
     }    
     var currentMenu:Array;
     switch(currentPage) {
         case Page.Main: currentMenu = mainMenu; break;
         case Page.Volume: currentMenu = volumeMenu; break;
         case Page.Confirm: currentMenu = confirmMenu; break;
         default: return;
     }
     GUI.FocusControl(currentMenu[selectedIndex]);
     
 }
  
 function PauseMenu() {
     BeginPage(screenWidth/2,screenHeight/2);
 
     GUI.skin = continue_skin;
     
     GUI.SetNextControlName("Continuar");
     if (GUILayout.Button ("")) {
         UnPauseGame();
  
     }
     
     GUI.skin = adjustVolume_skin;
     
     GUI.SetNextControlName("Volumen");
     if (GUILayout.Button ("")) {
         selectedIndex = 0;
         currentPage = Page.Volume;
     }
     
     GUI.skin = exit_skin;
     
     GUI.SetNextControlName("Salir");
     if (GUILayout.Button ("")) {
         selectedIndex = 0;
         currentPage = Page.Confirm;
     }
     
     EndPage();
 }
 
 function VolumeMenu() {
     
     BeginPage(screenWidth / 2, screenWidth / 2);
     GUI.skin = volumeBar_skin;
     
     GUILayout.Label("Volume");
     GUILayout.Space (20);
     GUI.SetNextControlName("Volume");
     AudioListener.volume = GUILayout.HorizontalSlider(AudioListener.volume,0.0,1.0);
     GUILayout.Space (20);
     GUI.skin = volumeMenu_skin;
     GUI.SetNextControlName("Go Back");
     if (GUILayout.Button("")) {
         selectedIndex = 0;
         currentPage = Page.Main;
     }
     
     EndPage();
 }
 
 function ConfirmationMenu(){
     
     BeginPage(screenWidth / 2 -400, screenHeight / 2);
     GUI.skin = confirm_skin;
     GUILayout.Label("Confirm that you want to go back to the Main Screen");
     GUILayout.Space(20);
     
     GUI.SetNextControlName("Confirmar");
     if (GUILayout.Button ("")) {
         Application.LoadLevel(MainMenu);    
     }
     
     GUI.skin = cancel_skin;
         
     GUI.SetNextControlName("Volver");
     if (GUILayout.Button("")) {
         selectedIndex = 0;
         currentPage = Page.Main;
     }
     
     EndPage();    
 }
  
 function BeginPage(width:int,height:int) {
     GUILayout.BeginArea(Rect((Screen.width - width)/2-50,(Screen.height - height)/2,width+200,height));
 }
 
 function EndPage() {
     GUILayout.EndArea();
 }
  
 function PauseGame() {
     
     savedTimeScale = Time.timeScale;
     Time.timeScale = 0;
     AudioListener.pause = true;
 
     currentPage = Page.Main;
     selectedIndex = 0;
     
     var pauseEndTime:float;
     pauseEndTime = Time.realtimeSinceStartup + menuClip.length + 0.1;
     
     playerAudio.PlayWithPriority(menuClip, 4);
     
     while (Time.realtimeSinceStartup < pauseEndTime) {
         yield 0;
     }
     
     if (IsGamePaused()) {
         playerAudio.PlayWithPriority(menuExplanationClip, 4);
     }
     
     pauseEndTime = Time.realtimeSinceStartup + menuExplanationClip.length + 0.1 ;
     
     while (Time.realtimeSinceStartup < pauseEndTime) {
         yield 0;
     }
     
     if (IsGamePaused()) {
         playerAudio.PlayWithPriority(defaultOptionClip, 4);
     }
 
 }
  
 function UnPauseGame() {
     playerAudio.audio.Stop();
     
     Time.timeScale = savedTimeScale;
     AudioListener.pause = false;
     currentPage = Page.None;
     
 }
  
 function IsGamePaused() {
     return Time.timeScale==0;
 }
  
 function OnApplicationPause(pause:boolean) {
     if (IsGamePaused()) {
         AudioListener.pause = true;
     }
 }

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sfc.itzhak · Jul 17, 2013 at 04:56 PM 0
Share

you have GUI.SetNextControlName("Go Back");

but in the strings you have private var volume$$anonymous$$enu:String[] = ["Volumen", "Volver"];

it should be private var volume$$anonymous$$enu:String[] = ["Volumen", "Go Back""];

sfc

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by sfc.itzhak · Jul 17, 2013 at 04:57 PM

in function VolumeMenu() you have GUI.SetNextControlName("Go Back");

but in the strings you have private var volumeMenu:String[] = ["Volumen", "Volver"];

it should be private var volumeMenu:String[] = ["Volumen", "Go Back""];

sfc

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image pabloromocl · Jul 17, 2013 at 07:01 PM 0
Share

Oh my godness. This was it! I just couldn't see it :/

Thanks, it works great now.

At least this script could be an example to make multiple menus for somebody.

Thanks

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to disable my Script and Gui 1 Answer

Resolutions 1 Answer

Texture Importer 3 Answers

targeting desnsity inside buoyancy script 0 Answers

Stand alone player 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges