Enemy Health bars through Script

Updated on July 8, 2019 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on June 19, 2017

Hi people, i already post this on Unity3D forum but no answers yet, So… and im stuck trying to add a health bar to the enemies, the way Brackeys do it on the video comsumes a lot of processing power and fps drops a loot because when an enemy spawn, and you have a lo~ot of enemies (more than 10) the performance of the game get worst and worst mostly because there’s a lot of canvas in the scene.
So… im trying the next:
 
I create an EnemyHPBar and make it a prefab, and make an instance of it and then make it children of an specific canvas called enemiesHealthBarCanvas and put the render mode WorldSpace.
On the enemy prefab i add a script called healthBarScript with the next code:

Click to Expand

 
On the inspector the enemy looks like this:

aslo the script of the enemy is the next one:
Click to Expand

 
and the script for enemyMovement is the next one:
Click to Expand

if someone could give some light to my problem i’ll be glad, if you need some more info let me know, in advance thanks for the help, and sorry for my bad english.

  • Liked by
Reply
1 on June 21, 2017

Well after read and think a lot, and someone from Unity Forums give me a litle idea, i figured out a way to do this, instead of using canvas and images,  i create a REALLY tiny plane on Bleder, imported to Unity and added to a empty GameObject, then i move the plane on X axis like 0.05 that way if you increase the empty GameObect X axis, the plane gonna increase by just one side. that way i be able to implement the healthbars on enemies.

Even if i spawn 500 enemies at 1000 rate the fps lost its REALLY small, and since there’s no way 500 at same time (i guess xD)  should be fine 😛 

Wise
on June 23, 2017

nice

Show more replies
  • Liked by
Reply
Cancel