1
NGUI 3 Support / Unable to Set Focus on a Button with UIButtons
« on: March 22, 2014, 12:36:28 PM »
Hi folks, I was hoping to get some help on using NGUI as a pause menu. Before I jump into the problems I'm having I'll do a quick runthrough of how I've gotten the pause menu into the scene.
Basically when the user presses the pause button the pause screen prefab is shown. I'm running into a fairly annoying problem that's affecting controller support, namely:
Any help on this matter would be greatly appreciated. I have the funny feeling this problem is a result of my inexperience with NGUI.
- using UnityEngine;
- using System.Collections;
- public class PauseGame : MonoBehaviour
- {
- // Boolean used to toggle pause and play.
- private bool pauseGame;
- private GameObject pauseScreen;
- void Start ()
- {
- // By default the game should not be paused.
- pauseGame = false;
- // Load the pause prefab into the scene.
- pauseScreen = (GameObject)Instantiate(Resources.Load("PauseMenu"));
- // Set the pause screen to invisible until the pause button is pressed.
- pauseScreen.SetActive(false);
- // Game proceeds normally when timeScale = 1.
- Time.timeScale = 1;
- // Disable seeing the cursor on-screen
- Screen.showCursor = false;
- }
- void Update ()
- {
- if(Input.GetButtonDown("Pause"))
- {
- // Either pause or unpause the game.
- // If the game isn't paused i.e. the player is playing, pause the game.
- if(pauseGame == false)
- {
- pauseScreen.SetActive(true);
- pauseGame = true;
- Time.timeScale = 0;
- Screen.showCursor = true;
- }
- // If game is paused and the pause button is pressed again, unpause.
- else if(pauseGame == true)
- {
- pauseScreen.SetActive(false);
- pauseGame = false;
- Time.timeScale = 1;
- Screen.showCursor = false;
- }
- }
- }
- }
Basically when the user presses the pause button the pause screen prefab is shown. I'm running into a fairly annoying problem that's affecting controller support, namely:
- I have the UIButton Keys script attached to my pause menu with the "Resume game" button listed as "start targeted". For some reason this isn't working, however. I think it may have something to do with the way I activate it - "pauseScreen.setActive(true)". Is this the correct way to call my pause screen?
Any help on this matter would be greatly appreciated. I have the funny feeling this problem is a result of my inexperience with NGUI.
