textfield for output

Hi there everyone

I can’t seem to find anywhere how you can use a GUI TextField for input as well as output. So, I want to display a value, but also when the variable change, the text input box must show that value

Thanks in advance

Doesnt the example provided in the documentation of GUI.TextField cover your topic?

Or are you changing the string somewhere else and the GUI is not updated without further interaction?

Thanks Marrrk

yes, I saw that example, but you were right about changing the value and I ended up doing this:

x = float.Parse(GUI.TextField(new Rect(750, 225, 100, 20), x.ToString()));

Thanks

You shuld use float.TryParse or else the whole thing will crash if someone types by accident a non-numeral:

var result = GUI.TextField(new Rect(750, 225, 100, 20), x.ToString());
float newValue;
if (float.TryParse(result, out newValue))
  x = newValue;

Got it, thanks!!!