- Home /
Question by
KittyAnn · May 08, 2019 at 04:09 PM ·
gui-button
Converting void OnGUI to my own buttons I make... PLEASE HELP!
Here is my script:
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()
{
//Get the player names in the array usernames at 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
//Below is all AUTO CREATED, which I do NOT like, but it works. I want to make my OWN buttons.
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];
}
}
}
}
}
I want to replace the auto button maker list of void OnGUI with buttons I make myself. Can someone PLEASE help me? I also do NOT want to use prefab buttons either.
Comment