Author Topic: Adding a life bar to an NPC  (Read 2732 times)

Darkness

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 90
    • View Profile
Adding a life bar to an NPC
« on: May 17, 2014, 05:45:59 AM »
When I first picked up NGUI, I was thinking about having NPCs put a bar on the side of the screen to show their HP.  After testing this, I've come to the conclusion that it would be better to simply have an HP bar above their head.

NGUI has changed a lot and now I'm wondering how can I do this?  I'm not even sure how to have a life bar anymore as all of my code is old and hasn't been updated (it still worked, so I saw no need to change it).  Do I use HUDText to accomplish this, or do I need to do something else?  Could anyone provide a bit of insight?

Thanks in advance.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Adding a life bar to an NPC
« Reply #1 on: May 17, 2014, 07:51:45 PM »
1. Create a game object in your 3D world above the NPC's "head". This will be your attachment point.
2. Create a health bar widget on your UI (a slider for example).
3. Anchor the slider widget to the "attachment point" using the "Anchors" field on the widget. If you have HUDText, you can actually use UIFollowTarget instead here.