Show live hunter/hider counts in match HUD
Count spawned role variants from a client-side avatar registry in NetworkPlayerSetup (network objects exist on every machine), so the counts work without server-only match state. MatchHud binds the two count texts and rewrites them only on change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
67f97df9f0
commit
6434e1c4fc
2 files changed
+38
-2
No files matched your search
@@ -31,14 +31,16 @@ public class MatchHud : MonoBehaviour
|
||||
[SerializeField] private GameObject _crosshair;
|
||||
|
||||
private int _lastSecond = -1;
|
||||
private int _lastHunters = -1;
|
||||
private int _lastHiders = -1;
|
||||
private MatchManager.MatchSubPhase _lastPhase = (MatchManager.MatchSubPhase)(-1);
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (!_canvas) _canvas = GetComponent<Canvas>();
|
||||
if (!_canvas || !_phaseText || !_timeText || !_crosshair)
|
||||
if (!_canvas || !_phaseText || !_timeText || !_crosshair || !_hunterCount || !_hiderCount)
|
||||
{
|
||||
Debug.LogError("[MatchHud] Unwired reference(s) - assign Canvas/Phase/Time/Crosshair in the Inspector.", this);
|
||||
Debug.LogError("[MatchHud] Unwired reference(s) - assign Canvas/Phase/Time/Crosshair/HunterCount/HiderCount in the Inspector.", this);
|
||||
enabled = false;
|
||||
return;
|
||||
}
|
||||
@@ -68,6 +70,18 @@ public class MatchHud : MonoBehaviour
|
||||
_timeText.text = $"{s / 60:0}:{s % 60:00}";
|
||||
}
|
||||
|
||||
NetworkPlayerSetup.CountRoles(out int hunters, out int hiders);
|
||||
if (hunters != _lastHunters)
|
||||
{
|
||||
_lastHunters = hunters;
|
||||
_hunterCount.text = hunters.ToString();
|
||||
}
|
||||
if (hiders != _lastHiders)
|
||||
{
|
||||
_lastHiders = hiders;
|
||||
_hiderCount.text = hiders.ToString();
|
||||
}
|
||||
|
||||
bool showCross = phase == MatchManager.MatchSubPhase.Seek && NetworkPlayerSetup.LocalViewerIsHunter();
|
||||
if (_crosshair.activeSelf != showCross) _crosshair.SetActive(showCross);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user