How to Move Healthbar with Player after Spawning with NetworkManager
Hi, this is my first post and I am new to Unity but quickly picking it up so any tips are appreciated.
I'm making a multiplayer game where players fight each other. I have healthbars in the form of UI images that degrade if you get attacked. They are also currently child classes of the player. My problem is that the players are free to move, flip, turn, etc. in free space and the health bar is always at positive Y relative to the player. This means that if the player flips upside down, "positive y" from the player becomes underneath it so the healthbar moves to below the player...
I have read on other posts that my solutions are to:
"Negate" the movement of the parent by transforming the healthbar in the opposite direction. However I have not been able to find a suitable fix that accounts for changes in rotation as well as position.
Make the healthbar not a child of the player and write a script that mimics the players position. This will not work for me since I am using the Network Manager to bring players into the game, which only allows you to spawn one gameobject, so I basically have to keep the healthbar as a child of the player.
I have tried instantiating the healthbar on player creation and it spawns into the world but does not follow the player with the script I have. Also I have not tested yet but I am not sure if having multiple people spawning into the world will confuse all of the healthbars. This is the closest solution I have so far so maybe someone can figure out how to spawn in the healthbar and then have it follow the player.
If anyone has a solution or can explain how to get my solution working I would really appreciate it!
Mostly all of my code is simple short, few-liners that I followed off of Google, but if anyone needs to see it I can post it and explain further. I am using C# if that helps.
Thanks