using Photon.Pun; using TMPro; using UnityEngine; using UnityEngine.UI; namespace cc.ivanli.pun01 { [RequireComponent(typeof(TMP_InputField))] public class PlayerNameInputField : MonoBehaviour { private const string playerNamePrefKey = "PlayerName"; public void Start() { string defaultName = string.Empty; TMP_InputField inputField = GetComponent(); if (inputField != null) { if (PlayerPrefs.HasKey(playerNamePrefKey)) { defaultName = PlayerPrefs.GetString(playerNamePrefKey); inputField.text = defaultName; } } PhotonNetwork.NickName = defaultName; } public void SetPlayerName(string value) { if (string.IsNullOrEmpty(value)) { Debug.LogError("Player Name is not null or empty"); return; } PhotonNetwork.NickName = value; PlayerPrefs.SetString(playerNamePrefKey, value); } } }