Health bars that appear when damage is taken

I prefer that enemy health bars don’t clutter the scene, so I suppress their appearance until damage is taken

The key lines are in EnemyHealthBar.Start
canvas = GetComponentInParent<Canvas>();
canvas.enabled = false;
and in EnemyHealthBar.Update
canvas.enabled = (health < 1) ? true : false;

Also, I found that the bars would rotate to weird angles. Removing the following line in EnemyUI.LateUpdate seems to fix the problem.
` transform.rotation = Quaternion.LookRotation(cameraToLookAt.transform.forward);

That is a very cool workaround for nesting prefabs.


Nice, I haven’t implemented it yet but I was planning to do something similar and only show the health bars when the enemy is attacking as with my camera you can see enemies before you enter their attack radius.

1 Like

Privacy & Terms