I have a GUI window rigged with buttons, that, when I play it they are shown already selected and I want them to remain unselected until the user selects them. Also, I want to know how to make a button remain disabled until all the fields in the GUI are filled up. I have the code here and hopefully you can help me.
using UnityEngine;
using System.Collections;
public class myTestGUI: MonoBehaviour {
enum Windows { window1, window2, window3 };
Windows currentWindow = Windows.window1;
string txtAge;
int genderSelectIndex;
string[] genderOptions = { "Male", "Female" };
void Awake()
{
InitializeMainWindowVariables();
}
/// <summary>
/// Main function where the GUI windows are created
/// </summary>
///
void OnGUI()
{
switch (currentWindow)
{
case Windows.window1:
SurveyWindow();
break;
case Windows.window2:
//set the next window
break;
}
}
/// <summary>
/// Displays the background survey that the user will fill out
/// </summary>
void SurveyWindow()
{
int windowWidth = 800;
int windowHeight = 600;
//// Make a background box
GUI.Box(new Rect((Screen.width / 2) - (windowWidth / 2),
(Screen.height / 2) - (windowHeight / 2),
windowWidth, windowHeight),
"My GUI");
GUI.Label(new Rect(600, 250, 150, 100), "Are you male or Female?");
genderSelectIndex = GUI.SelectionGrid(new Rect(600, 280, 150, 30), genderSelectIndex, genderOptions, 2);
GUI.Label(new Rect(600, 330, 100, 100), "How old are you?");
txtAge = GUI.TextField(new Rect(600, 355, 50, 40), txtAge, 2);
if (GUI.Button(new Rect(1250, 690, 100, 50), "Continue"))
{
//SendMessage("Background Survey Button Pressed");
currentWindow = Windows.window2;
}
}
void InitializeMainWindowVariables()
{
txtAge = string.Empty;
genderSelectIndex = 0;
}
}
@lokindia cool, I will definitely give it a go. Thanks!
– mmangual_83Knock, knock. How goes it?
– SpinnernicholasI figured it out thanks!
– mmangual_83