- Home /
How to make remote player's healthbar GUI look at local player's camera?
This is a multiplayer game with the player prefab which has a camera in it, as well as a health canvas that displays above the player's head.
The issue is, the local player and remote player both have cameras and health canvases inside of them. Of course, if I try to tell the health canvas to face the player's camera. It will just face it's own camera and not the local player's camera. The other player's health canvas should be facing your player's camera.
So I tried differentiating them by checking for the layer masks on the player objects.
[SerializeField]
private Canvas healthCanvas;
[SerializeField]
private Camera playerCam;
[SerializeField]
string remoteLayerName = "RemotePlayer";
[SerializeField]
string localLayerName = "LocalPlayer";
void Update()
{
if (healthCanvas.transform.parent.gameObject.layer == LayerMask.NameToLayer(localLayerName)
&& playerCam.transform.parent.gameObject.layer == LayerMask.NameToLayer(remoteLayerName))
healthCanvas.transform.LookAt(playerCam.transform);
}
However, this just doesn't get the player's healthCanvas to face the other player's camera.
I'm trying to get every remote player's health canvas to face the local player's camera for each local player on every frame.
Thanks.
Your answer
Follow this Question
Related Questions
Make so that a player cant see the players model? 1 Answer
Camera attached to the wrong player 1 Answer
Cinemachine Input Provider requires InputActionReference. Any workarounds? 0 Answers
camera doesnt follow player after I added networkIdentiy and networkTransform to the player 0 Answers
Multiplayer| Attaching camera to player (if i am the owner 1 Answer