Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Unity UI Text Field Input

Discussion in 'Scripting' started by Will-Metcher, Dec 18, 2014.

  1. Will-Metcher

    Will-Metcher

    Joined:
    Nov 15, 2014
    Posts:
    14
    Hey Guys
    Just a quick question, if I want to take the users input from an Input Field and place that value into a variable what do I need to do in JS. Setting it as an int would be preferable.
     
  2. ZO5KmUG6R

    ZO5KmUG6R

    Joined:
    Jul 15, 2010
    Posts:
    489
    The same prinicples apply in JS, the System.Convert and the int typecast. This should be easy enough to convert for your needs :)
    Code (CSharp):
    1. int numVariable = 0;
    2. void OnGUI(){
    3.    numVariable = System.Convert.ToInt32(GUI.TextField(new Rect(0,0,300,300),(string)numVariable));
    4. }
     
  3. Will-Metcher

    Will-Metcher

    Joined:
    Nov 15, 2014
    Posts:
    14
    void is not a valid macro...Please help