Hello, I am having an issue where I have a player health bar that when you press F it goes down. When there is only the Host on the server, the Health bar works as expected, however when the second player joins, the health bar bugs out and has a weird overlay that only works(not as expected) on the second player, but does not remove the red of the health bar.
Here is my health bar code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mirror;
using UnityEngine.UI;
public class HealthBar : NetworkBehaviour
{
public int CurrentHealth = 0;
public int MaxHealth = 100;
public Slider slider;
// Start is called before the first frame update
void Start()
{
Debug.Log(CurrentHealth = MaxHealth);
}
// Update is called once per frame
void Update()
{
if (!isLocalPlayer) return;
if (isLocalPlayer && Input.GetKeyDown(KeyCode.F))
{
Debug.Log("Reducing Health");
ReduceHealth();
}
if (isLocalPlayer && Input.GetKeyDown(KeyCode.G))
{
Debug.Log("Reviving");
Revive();
}
}
[Command]
void ReduceHealth()
{
Debug.Log(CurrentHealth -= 10);
slider.value = CurrentHealth;
}
[Command]
void Revive()
{
Debug.Log(CurrentHealth = MaxHealth);
slider.value = CurrentHealth;
}
}
This is an image of the game with one player:
And this is the one with two players:
If someone can help me out that would be great!
Also if you need me to give you more information on it, just ask what you need because I understand that this original post could be vague.
Edit: I think that the problem is that there are two canvas’s being spawned (one for each player) and they are both being shown on the screen, so what I would need to do is figure out how to only show the canvas that is for that player.
If someone knows if that is the issue or how to fix that let me know.