Arcade name input with two buttons
Hi! I'm making a highscore board but I'm having trouble with the name input, since I won't have a keyboard I have to work only with two buttons, one would change the character and the other will select it, making a three character string. That would be sent to the highscore board, but that I have figured it out. I have a Text field and I want to show the character when you're changing it, like a classic arcade game. Here's the code I have so far:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SetName : MonoBehaviour
{
public Text aText;
private int countKey;
private char[] alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
private char[] ABC;
private bool notSelected;
private bool doneSelection;
// Start is called before the first frame update
void Start()
{
notSelected = true;
doneSelection = false;
ABC = new char[3];
countKey = 0;
StartCoroutine("charName");
}
/// <summary>
/// Update is called every frame, if the MonoBehaviour is enabled.
/// </summary>
void Update()
{
if(doneSelection == true)
{
StopCoroutine("charName");
PlayerPrefs.SetString("PlayerName",ABC.ToString());
}
}
IEnumerable charName()
{
while(true)
{
for(int i = 0; i <= 3; i++)
{
notSelected = true;
while(notSelected == true)
{
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
if(countKey <= 26)
countKey++;
else countKey = 0;
aText.text = alpha[countKey].ToString();
}
if(Input.GetKeyDown(KeyCode.Space))
{
ABC[i]=alpha[countKey];
notSelected = false;
}
}
}
doneSelection = true;
}
}
}
I know I may have several mistakes but I'll be glad if someone could help me! :)
Comment