GUI.FloatField?

Is it possible to create a float field by using GUI.TextField?
I’m looking for exactly the same behavior as EditorGUI.FloatField, only have it work in the scene view.

I tried running the value from TextField, into the parse method and returning a float value, which sounds like it should work. However, it doesn’t. The issue is that I do this on every OnGUI, so when I enter a “.” (dot), the parse fails since 1. isn’t a float, while 1.x is. Copy-pasting a value into the field works, but typing it in doesn’t. Is there any way of accomplishing this or is there a link to repo somewhere that solved this? Here’s a simple snipper below.

float val = 0;
float.TryParse(GUI.TextField(floatRect, content.ToString()), out val);

return val;

You’ll have to store the string on its own, and try your parse on the stored string, not on content.ToString.

Sidenote, you should move away from using the obsolete OnGUI-based UI in runtime, it’s bad in every possible way (performance, reliability, look/feel, etc), and learn to use the Canvas-based UI instead.

1 Like