Author Topic: Instantiate health bar created for several enemies  (Read 2961 times)

Demigoth

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 18
    • View Profile
Instantiate health bar created for several enemies
« on: March 22, 2014, 06:39:16 PM »
Hey ArenMook,

So I created this healthbar with a progress bar, but I want to use this for all the enemies that spawn in my game, is there any way to assign it to the instances of the enemies and instantiate this object for each one of them?

Or do I need to create the healthbars outside the GUI? any help would be greatly appreciated!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Instantiate health bar created for several enemies
« Reply #1 on: March 23, 2014, 02:50:15 AM »
Each NPC would need to create its own instance of a health bar, adding it to the proper node in the UI hierarchy. Each NPC would also need to be responsible for updating the health bar's value.

Demigoth

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: Instantiate health bar created for several enemies
« Reply #2 on: March 23, 2014, 07:41:38 AM »
Hey ArenMook,

Have you ever tried this with a poolmanager? I mean all my enemies that spawn come from instances of a mob, how can I link which one updates which one.

Yukichu

  • Full Member
  • ***
  • Thank You
  • -Given: 3
  • -Receive: 8
  • Posts: 101
    • View Profile
Re: Instantiate health bar created for several enemies
« Reply #3 on: March 23, 2014, 01:56:23 PM »
I do it with a poolmanager.

I made a generic 'displayObject' nGUI prefab that has a name and a health bar.

Create pool of them.  Assign as needed for specific character, create a reference for it, update as needed.

Works wonderfully.

When player leaves, put displayObject back into pool.

Demigoth

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: Instantiate health bar created for several enemies
« Reply #4 on: March 26, 2014, 10:46:47 AM »
Hey Yukichu,

Can you give me a hand on how you do this?, the pool is a UI child, now how do I actually assign this spawned healthbar to the freshly spawned mob. how do I actually create this reference.