62 lines
1.5 KiB
C#
62 lines
1.5 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class UIManager : MonoBehaviour
|
|
{
|
|
[SerializeField] private Text scoreText;
|
|
[SerializeField] private Text positionText;
|
|
[SerializeField] private Text statusText;
|
|
[SerializeField] private Transform player;
|
|
[SerializeField] private int targetScore = 5;
|
|
|
|
public int CurrentScore { get; private set; }
|
|
public int TargetScore => targetScore;
|
|
|
|
private void Start()
|
|
{
|
|
UpdateScoreText();
|
|
SetStatus($"Собери {targetScore} сфер и доберись до синей зоны.");
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (player == null || positionText == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Vector3 position = player.position;
|
|
positionText.text = $"Position: X {position.x:F1} | Y {position.y:F1} | Z {position.z:F1}";
|
|
}
|
|
|
|
public void AddScore(int amount)
|
|
{
|
|
CurrentScore += amount;
|
|
UpdateScoreText();
|
|
|
|
if (CurrentScore < targetScore)
|
|
{
|
|
SetStatus($"Сфера собрана: {CurrentScore}/{targetScore}. Собери остальные.");
|
|
return;
|
|
}
|
|
|
|
SetStatus("Все сферы собраны. Двигайся к синей зоне.");
|
|
}
|
|
|
|
public void SetStatus(string message)
|
|
{
|
|
if (statusText != null)
|
|
{
|
|
statusText.text = message;
|
|
}
|
|
}
|
|
|
|
private void UpdateScoreText()
|
|
{
|
|
if (scoreText != null)
|
|
{
|
|
scoreText.text = $"Spheres: {CurrentScore}";
|
|
}
|
|
}
|
|
}
|