Files
PenguinsTwoChase/Assets/Scripts/Lobby/LobbyClientDisplayManager.cs
2026-05-20 21:11:09 +01:00

37 lines
1.3 KiB
C#

using PashaBibko.PenguinChase.Network;
using UnityEngine;
namespace PashaBibko.PenguinChase.Lobby
{
public class LobbyClientDisplayManager : MonoBehaviour
{
[Header("References")]
[SerializeField] private GameObject ClientDisplayPrefab;
[SerializeField] private GameObject ClientDisplayParent;
private int mCachedClientCount = -1; // Forces a refresh on initial load
private void Update()
{
// Checks if the client count has changed since last update
if (mCachedClientCount != GameNetworkClient.ConnectedClientCount)
{
// Clears all old client displays
foreach (Transform child in ClientDisplayParent.transform)
{
Destroy(child.gameObject);
}
// Creates new objects for each client
GameNetworkClient[] clients = GameNetworkClient.ConnectedClients;
foreach (GameNetworkClient client in clients)
{
GameObject go = Instantiate(ClientDisplayPrefab, ClientDisplayParent.transform);
LobbyClientDisplay display = go.GetComponent<LobbyClientDisplay>();
display.SetText(client);
}
}
}
}
}