71 lines
1.6 KiB
C#
71 lines
1.6 KiB
C#
// ScoreHUD.cs
|
|
// Zweck: Einfaches Score-HUD (Singleton): Punkte anzeigen, Sichtbarkeit toggeln.
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class ScoreHUD : MonoBehaviour
|
|
{
|
|
public static ScoreHUD Instance { get; private set; }
|
|
|
|
[Header("UI")]
|
|
[SerializeField] private CanvasGroup scoreCanvas; // Canvas/Panel
|
|
[SerializeField] private TMP_Text scoreLabel; // Punkte-Text
|
|
|
|
[Header("Settings")]
|
|
[SerializeField] private bool showAtStart = true; // Sichtbar am Start
|
|
|
|
private int _score;
|
|
|
|
private void Awake()
|
|
{
|
|
if (Instance != null && Instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
|
|
Instance = this;
|
|
|
|
UpdateScoreLabel();
|
|
UpdateVisibility();
|
|
}
|
|
|
|
// Punkt hinzufügen
|
|
public void AddPoint(int amount = 1)
|
|
{
|
|
_score += amount;
|
|
UpdateScoreLabel();
|
|
}
|
|
|
|
// Score zurücksetzen (neuer Run)
|
|
public void ResetScore()
|
|
{
|
|
_score = 0;
|
|
UpdateScoreLabel();
|
|
}
|
|
|
|
// Sichtbarkeit von außen (Optionsmenü)
|
|
public void SetVisible(bool visible)
|
|
{
|
|
showAtStart = visible;
|
|
UpdateVisibility();
|
|
}
|
|
|
|
private void UpdateVisibility()
|
|
{
|
|
if (!scoreCanvas) return;
|
|
|
|
scoreCanvas.gameObject.SetActive(showAtStart);
|
|
scoreCanvas.alpha = showAtStart ? 1f : 0f;
|
|
scoreCanvas.interactable = false;
|
|
scoreCanvas.blocksRaycasts = false;
|
|
}
|
|
|
|
private void UpdateScoreLabel()
|
|
{
|
|
if (scoreLabel) scoreLabel.text = _score.ToString();
|
|
}
|
|
|
|
public int CurrentScore => _score;
|
|
}
|