Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Health bar using netcode

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

  1. Talal88

    Talal88

    Joined:
    Jun 25, 2021
    Posts:
    4
    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. }