From 4c8534b7b36e77a7c7c47a10b163695686391739 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sun, 1 Feb 2026 10:13:56 +0800 Subject: 整合素材 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/UI/UIBinding.cs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Assets/Scripts/UI/UIBinding.cs (limited to 'Assets/Scripts/UI/UIBinding.cs') diff --git a/Assets/Scripts/UI/UIBinding.cs b/Assets/Scripts/UI/UIBinding.cs new file mode 100644 index 0000000..b84f307 --- /dev/null +++ b/Assets/Scripts/UI/UIBinding.cs @@ -0,0 +1,34 @@ +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; + } + } +} -- cgit