Around the end he changes the canvas render mode to World space. His was in 3d and mine is a 2D top down shooter.
I sized and placed the bar above an enemy, and made the bar a child of the enemy, it follows him… But, as the enemy turns around to chase the player the bar also make a weird turn and position it self below the enemy.
How can I achieve so it always stays on top of his head or exactly where I put it and ONLY follows the parent without any rotation or mis-possition
Don’t make the bar a child of the object it is supposed to follow. Instead you could create a script that makes the bar follow the enemy position so that it stays on the same position relative to the enemy. I am pretty sure if you google for such script you find some examples.
thank you. I did just that.
Now sometimes I experienced that if I kill the enemy’s to fast the healthbar don’t get destroyed and when the timer for removing the dead enemy’s kicks in, I get an error null reference on a Transform trying to be called. This transform is of course the health bar that no longer can find the dead enemy it is supposed to be on top of.
Perhaps you could just make a test in your health bar to see if the follow target exists. If not, it could even self destruct the health bar if you want that to happen. Just check if the transform’s GameObject you are following is null.