Search Unity

OnGUI.TextField(); not working to me [FIXED]

Discussion in 'Scripting' started by moynzy, Oct 30, 2014.

  1. moynzy

    moynzy

    Joined:
    Oct 22, 2014
    Posts:
    82
    Code (CSharp):
    1.         GUI.Label(new Rect(Screen.width/2 - 50,Screen.height/2, 50,30),"Name:");
    2.         playerName =  GUI.TextField(new Rect(Screen.width/2,Screen.height/2,100,30),"",20);
    3.  
    4.         if(GUI.Button(new Rect(Screen.width/2,Screen.height/2 + 40,100,30),"Play")){
    5.  
    6.             GameControl.control.playerName = playerName;
    7.             Debug.Log(GameControl.control.playerName);
    8.         }
    playerName is a class variable btw, made private ("private String playName;")

    Basically, when I click on the text field, it becomes non responsive.

    Everything displays too, or is because of my state machine?


    Code (CSharp):
    1.     void Start () {
    2.         pointsLeft = 10;
    3.         startScreenStates = StartScreneStates.CHARACTERSCREEN;
    4.     }
    5.    
    6.     // Update is called once per frame
    7.     void Update () {
    8.    
    9.     }
    10.  
    11.     void OnGUI(){
    12.         StartScreenStateMachine();
    13.        
    14.     }
    15.  
    16.     void StartScreenStateMachine(){
    17.  
    18.         switch(startScreenStates)
    19.         {
    20.             case StartScreneStates.TITLESCREEN:
    21.                 //Debug.Log("Press START");
    22.             ShowTitleScreen();
    23.                 break;
    24.             case StartScreneStates.STARTSCREEN:
    25.                 //Debug.Log("Press PLAY");
    26.             ShowGameOptions();
    27.                 break;
    28.             case StartScreneStates.CHARACTERSCREEN:
    29.                 //Debug.Log("ChooseCharacter");
    30.             ChooseCharacter();
    31.                 break;
    32.             case StartScreneStates.STATSSCREEN:
    33.                 //Debug.Log("Alocate Stats");
    34.             ChooseStatsAllocation();
    35.                 break;
    36.             case StartScreneStates.FINALSETUP:
    37.                 //Debug.Log("PLAY");
    38.                 //This is where it freezes when I want to enter name
    39.             EnterNameSave();
    40.                 break;
    41.         }
    42.     }
    Is anyone facing any problems with this?

    It worked fine before when I attempted it, but now I can't tell what is the problem.

    P.S - I have tried TextArea as well.
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
  3. moynzy

    moynzy

    Joined:
    Oct 22, 2014
    Posts:
    82