Search Unity

Input Text Field

Discussion in 'Immediate Mode GUI (IMGUI)' started by iceherosubzero, Aug 10, 2009.

  1. iceherosubzero

    iceherosubzero

    Joined:
    Jul 10, 2009
    Posts:
    36
    I want a input text field where i want the user to enter his name which later will appear in the profile he creates. How can I do that. I tried text field but in run time I am not able to enter and edit text. Please help Thanks.
     
  2. Quietus2

    Quietus2

    Joined:
    Mar 28, 2008
    Posts:
    2,058
    GUI.TextField works fine. I've used it many times for a player's name in high score tables, etc.

    You'll need to provide more information. Post the code your using along with what your expected and resultant behavior actually is. Simply saying, "Hi my text field doesn't work. What am I doing wrong", isn't nearly enough detail.
     
  3. iceherosubzero

    iceherosubzero

    Joined:
    Jul 10, 2009
    Posts:
    36
    GUI.Box (Rect ((Screen.width/2)-320, 200,Screen.width-(Screen.width/2),Screen.height-(Screen.height/2)), GUIContent("Create Profile" ));//"External Box"

    GUI.Label (Rect ((Screen.width/2)-30, 300,Screen.width-(Screen.width/2),Screen.height-(Screen.height/2)), "Enter Name");

    var textFieldString : String = "";
    textFieldString = GUI.TextField (Rect ((Screen.width/2)-250, 400, 500, 50), textFieldString); // Here if i pass some string in textFieldString which is my var it is displayed in the textfield but then i cannot edit or type the text in my text field.

    if (GUI.Button (Rect ((Screen.width/2)-50, 550,100,30), "Submit")) {
    // This code is executed when the Button is clicked
    print("Hello");}

    Please help
     
  4. Quietus2

    Quietus2

    Joined:
    Mar 28, 2008
    Posts:
    2,058
    OnGUI runs multiple times per frame and each time it does you're setting the value of the text field to null. Move the declaration of your string to somewhere in your class other than OnGUI.
     
  5. iceherosubzero

    iceherosubzero

    Joined:
    Jul 10, 2009
    Posts:
    36
    Thanks a lot man. such a silly mistake !! :wink:
    Hey and 1 more thing, i had asked about navigating through menus some 4-5 days back so if possible for you can you please send me a sample code for it

    For your STATE MACHINE IDEA.

    Thanks
     
  6. DanielCheril

    DanielCheril

    Joined:
    Aug 1, 2013
    Posts:
    2
    with out coding can create textfield.
     
  7. ibrendan

    ibrendan

    Joined:
    Feb 6, 2014
    Posts:
    2
    I'm having an issue with GUI.textfield. Keyboard input is painfully slow. Has anyone encountered this and have a fix?