Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by JustANormalGuy · Aug 16, 2011 at 10:00 AM · guibuttontextfieldtypeoutput

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges