- Home /
How to Load Dynamic Form Based on User Choice Selection
Hello Developers,
Please have a look at the snapshot below for getting idea what i wanted.
I want to create form using unity GUI where there will be 3 choices for sign up process:
Teacher
Student
Parent
I want these 3 options to be present in form of toggle choices(only any one can be selected). After selecting any choice among the three respective sign-up form will be loaded dynamically in the same scene. I am trying to achieve this in C#.
Looking for possible help from you all developers. Any help would be much appreciated.
Thanks in Advance.
Answer by ArkaneX · Feb 28, 2014 at 01:39 PM
The easiest option would be creating a UserType enum in your class and three methods for drawing custom forms for user types. And depending on userType value, you should call specific method.
Some basic code mixed with pseudocode:
enum UserType
{
Teacher,
Student,
Parent
}
private UserType _userType;
void OnGUI()
{
if(teacher button activated)
{
_userType = UserType.Teacher;
}
if(student button activated)
{
_userType = UserType.Student;
}
if(parent button activated)
{
_userType = UserType.Parent;
}
switch(_userType)
{
case UserType.Teacher:
ShowTeacherForm();
break;
case UserType.Student:
ShowStudentForm();
break;
case UserType.Parent:
ShowParentForm();
break;
}
}
For hint of how to create radio buttons in Unity GUI, please check this question.
Thank you very much. I got idea finally from your answer. Thank you very much ArkaneX.
Answer by RickyAh · Feb 28, 2014 at 01:41 PM
What you are looking for is something like a .NET RadioButton. There's no such component on Unity.
A selection grid provides a similar functionality
But if you need something that look like buttons, you'll need to use multiple EditorGUI.Toggle and store yourself the selected option when the user clicks an option.
Once you know which selection the user has made, drawing different things based on that selection should be easy.
Your answer
Follow this Question
Related Questions
using GUI scrollView for multiple onGUI functions 0 Answers
GUI Table View In Unity 5 Answers
Deselecting Textarea when button pressed 1 Answer
Gui Playing Audio Trouble 1 Answer
How can I view a gameObject through every other gameObject? 0 Answers