blob: b84f307d00d5ad4d675e51b7e1f2a4ca16f65050 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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;
}
}
}
|