Fix player name UI and persist name between menu scenes
This commit is contained in:
22
Assets/Scripts/ukazmeno.cs
Normal file
22
Assets/Scripts/ukazmeno.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user