Author Topic: Best way to handle mixed UI/Game Objects in 2D space?  (Read 1502 times)

Saxi

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 24
    • View Profile
Best way to handle mixed UI/Game Objects in 2D space?
« on: July 16, 2014, 11:50:10 PM »
I am trying to wrap my head around using nGUI with 2D games.

One scenario that confuses me, is when you have game elements (like player, enemy, obstacle) with UI elements like a health bar or hit numbers.  As far as I understand it, anything that uses nGUI has to fall under UI Root, but a player or enemy for example would be under the main camera.  How would you get the hit numbers/health bars (in my case crossword puzzle squares with label and input) to work with nGUI elements without having some of your game objects under main camera and some in UI Root because they have UI elements.  And how do you handle mobile aspect ratio issues when dealing with these two independant cameras.

It is confusing how to manage some objects under one camera and some under another when there is not a clear separation from UI and Game.

In my case, I have crossword puzzle squares but there are elements that do not have UI components that would be under the main camera but the squares are not really UI they are part of the game but just have UI objects on them.  This gets more confusing when trying to do something like a 2D platformer where you have all sorts of text and ui like elements mixed in with game view elements.

I assume one way is to throw everything under UI Root, is this the recommended way?  What is the best practice to handling objects that are not UI objects, but really game field objects with UI elements attached?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Best way to handle mixed UI/Game Objects in 2D space?
« Reply #1 on: July 17, 2014, 02:56:41 AM »
UIRoot is optional. What's needed is a UIPanel to actually draw the widgets. All widgets must be underneath a UIPanel in order for them to be visible. You can create a simple in-game UI by doing this:

1. New game object (ALT+SHIFT+N)
2. Attach a UIPanel to it.
3. Shrink it so that it's small in size -- say (0.01, 0.01, 0.01).
4. Add a widget to it (with it selected, ALT+SHIFT+S to add a sprite for example).

Which camera will draw this sprite is determined by the layer of its panel.