Search Unity

Question GUI.FloatField?

Discussion in 'Immediate Mode GUI (IMGUI)' started by Dextozz, Jul 15, 2020.

  1. Dextozz

    Dextozz

    Joined:
    Apr 8, 2018
    Posts:
    493
    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.

    Code (CSharp):
    1. float val = 0;
    2. float.TryParse(GUI.TextField(floatRect, content.ToString()), out val);
    3.  
    4. return val;