using System; using TMPro; using UnityEngine; using UnityEngine.UI; namespace UI { public class UIBinding : MonoBehaviour { public GameProgressManager progress; [Range(0, 1)] public float player1ScorePercent; [Range(0, 1)] public float player2ScorePercent; public TMP_Text timeText; public TMP_Text player1ScoreText; public TMP_Text player2ScoreText; public TMP_Text questionText; public Image player1ScoreDisplay; public Image player2ScoreDisplay; private void FixedUpdate() { // 更新时间文本 timeText.text = progress.time.ToString(); // 更新百分比 player1ScorePercent = Mathf.Clamp(progress.player1Score, 0, Single.MaxValue) * 1.0f / progress.questionMaxScore * 1.0f; player2ScorePercent = Mathf.Clamp(progress.player2Score, 0, Single.MaxValue) * 1.0f / progress.questionMaxScore * 1.0f; var targetPlayer1Amount = Mathf.Lerp(0.25f, 0.5f, player1ScorePercent); var targetPlayer2Amount = Mathf.Lerp(0.25f, 0.5f, player2ScorePercent); // 更新进度条 player1ScoreDisplay.fillAmount = targetPlayer1Amount; player2ScoreDisplay.fillAmount = targetPlayer2Amount; // 更新玩家分数显示 player1ScoreText.text = progress.player1Score.ToString(); player2ScoreText.text = progress.player2Score.ToString(); // 更新问题显示 questionText.text = progress.questionPlayer.currentQuestion.QuestionText; } } }