- Home /
Why do my GUI Layout Buttons not appear on screen?
Hello, I have been having trouble with the below code. What I am trying to do is to get my "Roster" button to display fields from a database as buttons that appear when the roster button is clicked. The database access is working through the debug logs I have included in the below code. Where the problem lies I believe is when the code reaches the GUILayout.BeginArea The buttons that are meant to be in this area don't appear and neither does Debug.Log ("pressed " + name).
The code is below and any help would be much appreciated. I have examined the brackets, and as far as I can see that is not the problem!
void OnGUI () {
//if the roster button is clicked then show the roster
if (GUI.Button (new Rect(20, 80, 80, 20), "Roster")) {
Debug.Log ("showing roster");
//find out how many records are in the sqlite table
string connectionString = "URI=file:" +Application.dataPath + "/db"; //Path to database.
IDbConnection dbcon;
dbcon = (IDbConnection) new SqliteConnection(connectionString);
dbcon.Open(); //Open connection to the database
IDbCommand cmd = dbcon.CreateCommand();
cmd.CommandText = "SELECT COUNT(*) FROM roster";
Debug.Log (cmd.CommandText);
int count = Convert.ToInt32 (cmd.ExecuteScalar()); //convert the string or scalar counting command to an integer value known as count
Debug.Log (count); //return the number of records in the roster table in the database
//database already has open connection to the database.
IDbCommand dbcmd2 = dbcon.CreateCommand();
string sql2 = "SELECT name " + "FROM roster";
dbcmd2.CommandText = sql2;
IDataReader reader2 = dbcmd2.ExecuteReader();
GUILayout.BeginArea(new Rect (100,25,150,300));
GUILayout.BeginVertical();
while(reader2.Read()) {
string name = reader2.GetString (0);
{
if( GUILayout.Button(name) )
{
Debug.Log ("pressed " + name);
}
}
}
GUILayout.EndVertical();
GUILayout.EndArea();
Your answer
Follow this Question
Related Questions
Drawing several BeginArea inside a BeginScrollview (GUILayout) produces an unexpected behaviour 1 Answer
GUI.Window error. InvalidOperationException: Hashtable.Enumerator: snapshot out of sync. 0 Answers
know GUILayout current screen position 2 Answers
"'UnityEngine.GUI.DoTextField' is inaccessible due to its protection level." 1 Answer
Grid of GUILayout buttons? 1 Answer