You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
HighGroundRoyaleNetcode/Assets/Scripts/Gameplay/UI/PlayerName.cs

45 lines
1.2 KiB
C#

using System.Collections;
using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class PlayerName : MonoBehaviour
{
public TMP_InputField inputField; // Reference to the InputField
public Button submitButton; // Reference to the Button
public GameObject Panel;
public static event Action nameEntered;
void Start()
{
Starter();
}
void Starter()
{
if (PlayerPrefs.GetInt("PlayerNameSaved") == 0)
{
Panel.SetActive(true);
submitButton.interactable = false;
// Add a listener to detect input changes
inputField.onValueChanged.AddListener(delegate { ToggleButtonState(); });
}
}
void ToggleButtonState()
{
// Enable the button if input is not empty, disable otherwise
submitButton.interactable = !string.IsNullOrEmpty(inputField.text);
}
public void SaveName()
{
PlayerPrefs.SetInt("PlayerNameSaved", 1);
Debug.Log("Name that is saved is: " + inputField.text.ToString());
PlayerPrefs.SetString("PlayerName", inputField.text.ToString());
nameEntered?.Invoke();
Panel.SetActive(false);
}
}