Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Gambit · Mar 17, 2011 at 02:54 PM · nametextfield

Textfield problems.

hey :)

so im having some pretty annoying problems with the GUI.Textfield.

var InitSpawn : boolean = true; var ShowInitMenu : boolean = true; var Name : String = "John";

function OnGUI () {

 if (ShowInitMenu == true){
     if (InitSpawn == true){
         Submit = GUI.Button(Rect(Screen.width/2+5, Screen.height/2+25, 165, 25), "Finished");
         EnterName = GUI.TextField(Rect(Screen.width/2, Screen.height/2, 175, 60), "Enter A Name"); // show name field

         if (Submit){ // submit button
             if (EnterName == ""){
                 Name = "John"; // if the player didnt enter anythign default the name
             }
             else{
                 Name = EnterName;   // change the players name
             };

             ShowInitMenu = false;
         };
     }
     else{
         return;
     };          
 }
 else{
     return;
 };  

};

originally it was just the EnterName field what was a var, but i had to make the button a var and put it first so you could click it.

problem im having is that you cant edit the text field :(

i need it for my name system. when you die, it prints: "Enter A Name Died"

is the text field meant to have dynamic text in it? (able to be changed) am i using it wrong D:?

help please thanks.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Skjalg · Mar 17, 2011 at 03:05 PM

you gotta keep in mind how unity handles the GUI. think of it in terms of a really slow motion.

1st frame, your textfield has the text "Enter a Name", and when the user tries to type something in the field that text gets stored into the variable called EnterName.

2nd frame, your textfield has the text "Enter a name", since EnterName didnt get stored anywhere, and wasnt inserted into the textfield.

So basically the solution to your problem would be something along these lines:

var InitSpawn : boolean = true; var ShowInitMenu : boolean = true; var Name : String = "John"; var EnterName: String = "Enter A Name";

function OnGUI () { if (ShowInitMenu == true){ if (InitSpawn == true){ Submit = GUI.Button(Rect(Screen.width/2+5, Screen.height/2+25, 165, 25), "Finished"); EnterName = GUI.TextField(Rect(Screen.width/2, Screen.height/2, 175, 60), EnterName); // show name field if (Submit){ // submit button if (EnterName == ""){ Name = "John"; // if the player didnt enter anythign default the name } else{ Name = EnterName; // change the players name }; ShowInitMenu = false; }; } else{ return; }; } else{ return; }; };

Comment
Add comment · Show 2 · Share
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
avatar image Gambit · Mar 17, 2011 at 03:12 PM 0
Share

Awesome thanks heaps :D also..is there anyway to freeze the screen from moving until you click submit? i tried Screen.lockcursor = true and it did nothing >> i need to stop the screen from moving while that form is active.

avatar image Skjalg · Mar 20, 2011 at 12:44 PM 0
Share

I dont understand the question. Perhaps "Ask" a new question that is unrelated to this one?

Also, if the above answer is the correct one then you should specify that by clicking the V

avatar image
0

Answer by yoyo · Mar 17, 2011 at 03:03 PM

You need to pass the text field the current value of your text.

Something like ...

var InitSpawn : boolean = true; var ShowInitMenu : boolean = true; var Name : String = "Enter A Name";

function OnGUI () {

 if (ShowInitMenu){
     if (InitSpawn){
         Submit = GUI.Button(Rect(Screen.width/2+5, Screen.height/2+25, 165, 25), "Finished");
         Name = GUI.TextField(Rect(Screen.width/2, Screen.height/2, 175, 60), Name);

         if (Submit){ // submit button
             if (Name == "Enter A Name"){
                 Name = "John"; // if the player didnt enter anythign default the name
             }

             ShowInitMenu = false;
         }
     }
 }

}

Comment
Add comment · Share
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

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

No one has followed this question yet.

Related Questions

HighScore Names 1 Answer

Set name for game 0 Answers

In-game Player username 1 Answer

how to put the name of a car ??? 0 Answers

Calling prefabs by name or tag returns null. 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