Author Topic: Reccomended way to show/hide panels  (Read 6406 times)

Petroz

  • Guest
Reccomended way to show/hide panels
« on: May 22, 2012, 03:38:07 AM »
Currently I have a few menus in my game and I have a central GUIManager singleton which finds the NGUI Panels using GameObject.Find and GetComponent<>. This is quite ugly and I don't like the hard coded paths in my code. What is the reccomended way to show and hide panels using NGUI? Is there some message I can broadcast that could trigger a tween or something along those lines?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Reccomended way to show/hide panels
« Reply #1 on: May 22, 2012, 09:13:43 AM »
Broadcast won't work for disabled game objects. What you want instead is to have a central manager script residing on a game object. This script should be a singleton, and it should have public references to the panels you want to enable/disable. You can then access that script via its singleton and enable/disable what you wish.

For Windward I actually took it one step forward and have a function I broadcast which gets picked up by the menu selector, which then enables/disables things accordingly. This way I don't need a singleton.

Petroz

  • Guest
Re: Reccomended way to show/hide panels
« Reply #2 on: May 22, 2012, 04:35:29 PM »
Thanks for the reply. I guess public references would tidy up those hardcoded paths I'm using with GameObject.Find. It's good to know I'm not doing it completely wrong.

I really enjoyed playing Windward and look forward to future updates. :)