x


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.

more ▼

asked Aug 16 '11 at 10:00 AM

JustANormalGuy gravatar image

JustANormalGuy
1 2 2 3

(comments are locked)
10|3000 characters needed characters left

0 answers: sort oldest
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3673
x786
x149
x132
x34

asked: Aug 16 '11 at 10:00 AM

Seen: 653 times

Last Updated: Aug 20 '11 at 10:58 PM