summaryrefslogtreecommitdiff
path: root/Assets/Scripts/UI/UIBinding.cs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-02-01 10:13:56 +0800
committer魏曹先生 <1992414357@qq.com>2026-02-01 10:13:56 +0800
commit4c8534b7b36e77a7c7c47a10b163695686391739 (patch)
treed5399ddb195252b63292bdf62eadc2a0a64f56f9 /Assets/Scripts/UI/UIBinding.cs
parent7100bf815bd4458f5e40a2c992e915f15bd6efa9 (diff)
整合素材
Diffstat (limited to 'Assets/Scripts/UI/UIBinding.cs')
-rw-r--r--Assets/Scripts/UI/UIBinding.cs34
1 files changed, 34 insertions, 0 deletions
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;
+ }
+ }
+}