Search Unity

Health bar using netcode

Discussion in 'Multiplayer' started by Talal88, Mar 11, 2023.

  1. Talal88

    Talal88

    Joined:
    Jun 25, 2021
    Posts:
    7
    Hey all, I'm implementing a health bar, which is a slider on canvas attached to the player prefab. When the game starts, the host has a healthbar correctly displayed on their Ui, however when the client spawns, a second healthbar gets superimposed on top of the first one (on the host).

    Any idea how I might fix this issue?
     
  2. Burgler02

    Burgler02

    Joined:
    Dec 7, 2021
    Posts:
    1
    Probably too late, but you can just disable the UI game object if player is not it's owner.


    Code (CSharp):
    1. public override void OnNetworkSpawn()
    2. {
    3.     if(!IsOwner)
    4.     {
    5.         yourGameObjectReference.SetActive(false);
    6.     }
    7. }
     
    abhishek1987 likes this.