Fix player name UI and persist name between menu scenes

This commit is contained in:
gravitrax-bublina
2026-05-17 12:34:22 +02:00
parent 207f997254
commit 54bfcf745b
5 changed files with 51 additions and 12 deletions

View File

@@ -0,0 +1,22 @@
using UnityEngine;
using TMPro;
public class ukazmeno : MonoBehaviour
{
[SerializeField] private TMP_Text target;
[SerializeField] private string prefix = "name: ";
void Start()
{
if (target == null)
target = GetComponent<TMP_Text>();
string saved = PlayerPrefs.GetString("PlayerName", "");
if (string.IsNullOrWhiteSpace(saved) && GameManager.Instance != null)
saved = GameManager.Instance.displayName;
if (target != null)
target.text = string.IsNullOrWhiteSpace(saved) ? prefix : prefix + saved;
}
}