How to input float in textfiled and and let the scrollbar change its value at the same time

Hello, everyone.I wanna to draw a Scrollbar and a textfield at the same time.And when the Scrollbar scroll, the textfield’s value change with it, also, when the textfield’s text changed, the Scrollbar change its position too. I write the code like this:

            GUILayout.BeginVertical();
            GUILayout.Label("目间距");
            _interocularDis = GUILayout.HorizontalScrollbar(_interocularDis, 0.01f, 0, 1f);
            _interocularDis = (float)Math.Round(_interocularDis, digit1);

            string textInterocular = GUILayout.TextField(_interocularDis.ToString());
            try
            {
                _interocularDis = (float)Math.Round(_interocularDis, digit1);    
                
                //float tmp = float.Parse(textInterocular, System.Globalization.NumberStyles.AllowDecimalPoint);
                float tmp = 0.0f;
                float.TryParse(textInterocular, out tmp);
                _interocularDis = tmp;

               // _interocularDis = (float)Convert.ToDouble(textInterocular);
                
            }
            catch (Exception e)
            {
            }
        }
        GUILayout.EndVertical();

However, i can not input a float number in the textfield, how can i input a float number in the textfield and let the scrollbar change its value at the same time?
Any answer will be appreciate!

You are redefining “textInterocular” instead of just fetching the data.

Define the variable before calling the TextField() function or do that outside of the scope if you need to know of it outside of this scope:

// Defined
string textInterocular

GUILayout.BeginVertical();
   GUILayout.Label("目间距");
     _interocularDis = GUILayout.HorizontalScrollbar(_interocularDis, 0.01f, 0, 1f);
     _interocularDis = (float)Math.Round(_interocularDis, digit1);

      // now you can change the value
      textInterocular = GUILayout.TextField(_interocularDis.ToString());
            try
            {
                _interocularDis = (float)Math.Round(_interocularDis, digit1);    

                //float tmp = float.Parse(textInterocular, System.Globalization.NumberStyles.AllowDecimalPoint);
                float tmp = 0.0f;
                float.TryParse(textInterocular, out tmp);
                _interocularDis = tmp;

               // _interocularDis = (float)Convert.ToDouble(textInterocular);

            }
            catch (Exception e)
            {
            }
        }
        GUILayout.EndVertical();