Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: RyuuzakiBjorn on February 18, 2014, 12:51:20 PM

Title: Using NGUI for pause menu
Post by: RyuuzakiBjorn on February 18, 2014, 12:51:20 PM
Hi everyone, this is my first post!
I've got a little question which I can't seem to figure out the answer to, and was wondering if you guys 'n gals can help me out.
I've created a GUI in UIRoot for a pause menu. I've created a script to pause the game but I'm unsure how I can make the NGUI UI appear when the pause button is pressed and dissapear when players press the pause button again.

It sounds so simple, but I can't figure it out.

My current code:
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Pause : MonoBehaviour {
  5.  
  6.         private bool pauseEnabled = false;             
  7.        
  8.         void  Start (){
  9.                 pauseEnabled = false;
  10.                 Time.timeScale = 1;
  11.                 AudioListener.volume = 1;
  12.                 Screen.showCursor = false;
  13.         }
  14.        
  15.         void  Update (){
  16.                
  17.                 if(Input.GetButtonDown ("pauseButton")){
  18.                        
  19.                         if(pauseEnabled == true){
  20.                                 pauseEnabled = false;
  21.                                 Time.timeScale = 1;
  22.                                 AudioListener.volume = 1;
  23.                                 Screen.showCursor = false;                     
  24.                         }
  25.                        
  26.                         else if(pauseEnabled == false){
  27.                                 pauseEnabled = true;
  28.                                 AudioListener.volume = 0;
  29.                                 Time.timeScale = 0;
  30.                                 Screen.showCursor = true;
  31.                         }
  32.                 }
  33.         }
  34. }

How would I make it hide/unhide my NGUI ui when the game is paused?

Thanks in advance for the help!
- R
Title: Re: Using NGUI for pause menu
Post by: Litherad on February 19, 2014, 08:42:56 AM
An easy way would be to add a TweenAlpha to your root panel, start with alpha = 0 and then hit Play(pauseEnabled);
Title: Re: Using NGUI for pause menu
Post by: ArenMook on February 19, 2014, 03:48:41 PM
  1. TweenAlpha.Begin(panelGameObject, duration, targetAlpha);
...where 'duration' is how quickly you want it to fade in or out, and 'targetAlpha' is either 0 or 1 depending on what you want it to be.