Files
QuizzinMk5.1/Assets/Quiz/Scripts/Scoreboards/ScoreboardRowSpawner.cs

46 lines
1.4 KiB
C#

using UdonSharp;
using UnityEngine;
using UnityEngine.SocialPlatforms.Impl;
using UnityEngine.UI;
using VRC.SDKBase;
using VRC.Udon;
public class ScoreboardRowSpawner : Scoreboard
{
public GameObject rowPrefab;
public Transform rowContainer;
public override void UpdateScoreboard()
{
foreach (Transform child in rowContainer)
{
Destroy(child.gameObject);
}
VRCPlayerApi[] players = playerManager.GetCurrentPlayers();
foreach (VRCPlayerApi player in players)
{
GameObject newRow = Instantiate(rowPrefab, rowContainer);
TMPro.TMP_Text[] textComponents = newRow.GetComponentsInChildren<TMPro.TMP_Text>();
if (textComponents.Length > 0)
{
textComponents[0].text = player.displayName;
}
if (textComponents.Length > 1)
{
textComponents[1].text = playerManager.GetScore(player.playerId).ToString();
}
Image backgroundComponent = newRow.GetComponent<Image>();
if (backgroundComponent != null)
{
backgroundComponent.color = playerManager.GetTeam(player.playerId) == "red" ?
new Color(1f, 0f, 0f, 0.5f) : playerManager.GetTeam(player.playerId) == "blue" ? new Color(0f, 0f, 1f, 0.5f) : new Color(0.5f, 0.5f, 0.5f, 0.5f);
}
}
}
}