**How do I replace the void OnGUI with buttons I make myself in my code below?**
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SelectUsername : MonoBehaviour
{
public static int userNumber = -1; //current user (<0 means nothing selected)
public static string userName = "";
string[] usernames;
int numUsers = 0;
// Start is called before the first frame update
void Start()
{
numUsers = PlayerPrefs.GetInt("NumUsers", 0); // how many registered users?
usernames = new string[numUsers + 1]; //create user name list...
for (int n = 1; n <= numUsers; n++)
{
usernames[n] = PlayerPrefs.GetString("User" + n); // ...and load them.
}
}
// Update is called once per frame
void OnGUI()
{
if (userNumber < 0) //if any number isn't defined yet do the following
{
Rect r = new Rect(300, 300, 300, 100); // create basic rectangle
GUI.Label(r, "Select User");
for (int n = 1; n <= numUsers; n++)
{
r.y += 100; // offset rect to the next line
if (GUI.Button(r, usernames[n]))
{
// if user selected...
userNumber = n; // save number...
userName = usernames[n];
}
}
}
}
}
**AND how do I display the user's name in my own textbox on the main screen? I know how to do it for only 1 registered user, but am having the worst time telling the PlayerPrefs which user is selected. Can someone PLEASE show mercy on me?**
↧