Ok so after the the luxury of developing and testing on host client I have come to realize some problems that occur on clients that aren’t the host client. One of which is my hp bar.
Ok so I have a canvas attached above a player prefab with the hp bar and a script to make it face the camera.
I have a Player class that is responsible for feeding the correct variables to the hp bar scripts. The player class in created on the NetworkManager after creating the player prefab that contains a NetworkBehaviour PlayerController. It creates player object, and runs PlayerContoller.Init(player) to set its player variable. The hp script pulls from there, playercontoller.player.health example.
I will show you my scripts, please if someone can help me figure out how to solve this networking error I would be highly appreciative. Here we go.
PlayerHealthUI https://pastebin.com/dl/AHGzAnJN
NetworkController https://pastebin.com/dl/0pdGZLRt
CameraFacingBillboard https://pastebin.com/dl/MiN48nfE
PlayerController https://pastebin.com/dl/H51DmCUR
Player https://pastebin.com/dl/kCKaW3zG
Please let me know if there was something else I missed or need to share to help solve this problem. Thank you
I won’t do a whole rewrite of player, and I don’t want it to be derived from networkbehaviour. So does that mean I can’t possibly sync the variables correctly? Surely not.
Strange is that everything updates and works as expected on host client. I can see the players hp bar, and I can see him take the damage, he just doesn’t see my hp bar or my damage, but the transform position is updated properly… I just don’t get it…
You should post relevant code directly into the forum with code tags. As it is I get errors when clicking on your links.
If you don’t want to sync data using the NetworkBehaviour features such as SyncVar and ClientRpc, you can send Unet Messages from a MonoBehaviour, but you’ll need to write code to process those messages.
The links above work just fine for me. I didn’t put them in code tags on here because it would take multiple post due to the character limit. As far as using messages from MonoBehaviour, still defeats the purpose. I prefer most my classes being able to be constructed, and as it is, I would still have to do a major rewrite of player, and player controller and everything that works that is directly tied to player in code as it is.
Could I not reference the variables from player, in a networkbehaviour and then make it a sync var? How would I make sure the variables on the networkbehaviour are realtime from the player?