- Home /
Type in TextField to make buttons press and vice versa
When I press the above buttons on the GUI (the main menu in the game), letters appear in a textfield at the bottom of the menu. There's just one problem- I would like to type letters into the textfield and, depending on the numbers I entered, the buttons above will be pressed. Each time I try, I cannot configure it. When I try, I cannot type in the text field, as I am constantly assigning a value to the items in the field. Clicking buttons will assign letters- that part is easy. I want to have the choice to press the buttons or paste in a letter combination. I will also have many more parameters which means that I will need many more "letter#" variables, or else I would not go through all of this trouble. Thank you very much for your knowledge and time.
//drag this javascript onto the main camera, which should be the only thing in the scene
//var classCode: String;
var classCode = ""; public static var playerName = "N. A. B."; var primaryWeapon = "Pistol"; var letter1 = ""; var letter2 = ""; var letter1hold = ""; var letter2hold = "";
var toolbarInt = 0; var toolbarStrings : String[] = ["Team 1","Team 2"];
function OnGUI () { //instructions at top GUI.Label(Rect(100,25,150,30),"Create Your Soldier"); //display health at bottom
//label "Player Name"
GUI.Label(Rect(100,50,100,30), "Player Name");
//Type in Player Name
playerName = GUI.TextField(Rect(200,50,100,25),playerName);
//buttons for "Team 1" and "Team 2"
toolbarInt = GUI.Toolbar(Rect(100,75,250,25),
toolbarInt,toolbarStrings);
if (toolbarInt == 0)
{
letter1 = "A";
}
if (toolbarInt == 1)
{
letter1 = "B";
}
//display Primary Weapons, print to label
if (GUI.Button (Rect (200, 100, 100, 30), "Launcher"))
{
primaryWeapon = "Launcher";
letter2 = "L";
}
if (GUI.Button (Rect (100, 100, 100, 30), "Pistol"))
{
primaryWeapon = "Pistol";
letter2 = "P";
}
//display primary weapon at bottom
GUI.Label(Rect(100,475,100,25), primaryWeapon);
//display text box for code
//make: when you click in the box, it highlights all, (search bar?)
classCode = GUI.TextField(Rect(100,500,100,25),
letter1 + letter2);//THIS TextField is it!
//make: when typing in code, it selects buttons for you
// if(letter1=="A") toolbarInt = 0; // if(letter1=="B") toolbarInt = 1; // if(letter2=="L") primaryWeapon = "Launcher"; // if(letter2=="P") primaryWeapon = "Pistol";
//reset button
if (GUI.Button (Rect (200, 500, 50, 25), "Reset"))
{
classCode = "";
}
}
Typing in "AL" into the textField should put you on team A and give you a launcher.
Your answer
Follow this Question
Related Questions
Problem with GUI.Button and other GUI items 1 Answer
GUI.Textfield backspace control + Button Style problem 0 Answers
GUI button working with GUI Textfield 0 Answers
How do I set a button to exit a GUI text field 0 Answers
textfield and button submit 1 Answer