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 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; } } }