Author Topic: Switch from Menus to Standard Elements  (Read 6444 times)

redhawk

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 34
    • View Profile
Switch from Menus to Standard Elements
« on: October 07, 2013, 01:57:41 PM »
How should I set up my project so that all of my standard NGUI elements are shown during play (like health, health bar, life, Ammo, Experience, Treasure) and only menus when in "menu mode" (like I died, so Main Menu comes up and game is paused, or I hit escape and Main Menu comes up)?

I've watched the videos but I still don't understand how to do this.  I have my "standard elements" all set up and looking really awesome (and functioning well during game play).  Not sure what I need to next so that if I die, or hit escape, the Main menu opens.  I can make the game pause on escape or death, but what next??

Please help :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Switch from Menus to Standard Elements
« Reply #1 on: October 08, 2013, 01:45:30 AM »
Switching from menus to standard elements? That doesn't make much sense to me. Assuming you have two panels -- one for your HUD elements, and another for your menu window... just TweenAlpha one in, TweenAlpha the other out.

redhawk

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: Switch from Menus to Standard Elements
« Reply #2 on: October 08, 2013, 07:47:37 PM »
Here's how I solved this.

First I watched the latest video which is about Modular User Interface.
http://youtu.be/q1C5NwZasGs

I created my background sprite (super useful), a "window" for the container, and some buttons.  I added 2 buttons - one to Play/Resume, one to go to another window.  I duplicated this window.  I called one window Main Menu, the other Options Menu. 

Options Button or Main Menu Button - I added UIButton Activate Script twice.  First targets Window to deactivate/hide (State not checked).  Second targets Window to active/show (State checked).

Play Button - 1 UIButton Activate script.  Deactivates the main Panel that all of this is set up on (State not checked).

I looked at the UIButton Activate script, pulled out the necessary components and created the below script which is 100% based on the NGUI script.  I created a cube and stuck this script on it.

Hit escape, and the menu opens.
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. //Based on UIButtonActivate NGUI Script
  5.  
  6. [AddComponentMenu("NGUI/Interaction/Button Activate")]
  7. public class OpenMainMenu : MonoBehaviour {
  8.        
  9.         public GameObject target; //What do we want to activate
  10.     public bool state = true; //True will activate, false will deactivate
  11.        
  12.         // Update is called once per frame
  13.         void Update () {
  14.        
  15.                 if(Input.GetKeyDown(KeyCode.Escape))
  16.                 {
  17.                         //If target has not been set, the do nothing
  18.                         if (target != null) NGUITools.SetActive(target, state);
  19.                 }
  20.                
  21.         }
  22. }

redhawk

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: Switch from Menus to Standard Elements
« Reply #3 on: October 08, 2013, 07:52:21 PM »
Attached is what my test window looks like.  Super basic.  The Label main menu and all items in the blue box are all under the parent of the blue box which I call "WindowMain"