You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.1 KiB
C#

using UnityEngine;
using UnityEngine.UI;
namespace Class03
{
// 점수 변경을 화면 텍스트에 반영하는 역할만 합니다.
public sealed class ScoreView : MonoBehaviour
{
[SerializeField] private ScoreCounter counter;
[SerializeField] private Text scoreText;
[SerializeField] private Text statusText;
public void Initialize(ScoreCounter source, Text score, Text status)
{
counter = source;
scoreText = score;
statusText = status;
}
private void OnEnable()
{
if (counter == null) return;
counter.Changed += Refresh;
Refresh(counter.Score, counter.TargetScore);
}
private void OnDisable()
{
if (counter != null) counter.Changed -= Refresh;
}
private void Refresh(int score, int target)
{
scoreText.text = $"STARS {score:00} / {target:00}";
statusText.text = score >= target ? "ALL STARS COLLECTED!" : "ROLL. EXPLORE. COLLECT.";
}
}
}