- Home /
OnGUI using UnityEditor how to make FloatField work?
I want to give player options to have long float for mouse sensitivity and I do not want to restrict him
so my approach is giving him float and I'm kinda heaving problems
I was following this but I was heaving problems getting in .
I was following this but if I entered strange value I couldn't repair it nor could I make float less big if needed like 15 or 15.1 and not 15.00
I was following this and tried to use that in answer but somehow I always got in to problem
than I followed this found my solution but just don't understand it properly tho I have hard times understanding Java and even more I have hard time understanding new complicated stuff with too much useless info I like to see only what is necessary for something to work
my code
using UnityEngine;
using System.Collections;
using UnityEditor;
public class GuiFloat : MonoBehaviour {
public float Length = 0;
public float newLength = 0;
void OnGUI(){
newLength = EditorGUILayout.FloatField(Length);
}
}
I'm getting error when I click the box
NullReferenceException: Object reference not set to an instance of an object
UnityEditor.EditorGUI+RecycledTextEditor.IsEditingControl (Int32 id) (at C:/BuildAgent/work/812c4f5049264fad/Editor/MonoGenerated/Editor/EditorGUI.cs:152)
UnityEditor.EditorGUI.DoNumberField (UnityEditor.RecycledTextEditor editor, Rect position, Rect dragHotZone, Int32 id, Boolean isFloat, System.Single& floatVal, System.Int32& intVal, System.String formatString, UnityEngine.GUIStyle style, Boolean draggable, Single dragSensitivity) (at C:/BuildAgent/work/812c4f5049264fad/Editor/MonoGenerated/Editor/EditorGUI.cs:1164)
UnityEditor.EditorGUI.DoFloatField (UnityEditor.RecycledTextEditor editor, Rect position, Rect dragHotZone, Int32 id, Single value, System.String formatString, UnityEngine.GUIStyle style, Boolean draggable, Single dragSensitivity) (at C:/BuildAgent/work/812c4f5049264fad/Editor/MonoGenerated/Editor/EditorGUI.cs:1144)
UnityEditor.EditorGUI.DoFloatField (UnityEditor.RecycledTextEditor editor, Rect position, Rect dragHotZone, Int32 id, Single value, System.String formatString, UnityEngine.GUIStyle style, Boolean draggable) (at C:/BuildAgent/work/812c4f5049264fad/Editor/MonoGenerated/Editor/EditorGUI.cs:1139)
UnityEditor.EditorGUI.FloatField (Rect position, Single value, UnityEngine.GUIStyle style) (at C:/BuildAgent/work/812c4f5049264fad/Editor/MonoGenerated/Editor/EditorGUI.cs:1013)
UnityEditor.EditorGUI.FloatField (Rect position, Single value) (at C:/BuildAgent/work/812c4f5049264fad/Editor/MonoGenerated/Editor/EditorGUI.cs:1009)
UnityEditor.EditorGUILayout.FloatField (Single value, UnityEngine.GUILayoutOption[] options) (at C:/BuildAgent/work/812c4f5049264fad/Editor/MonoGenerated/Editor/EditorGUI.cs:3433)
GuiFloat.OnGUI () (at Assets/GuiFloat.cs:10)
Answer by OWiz · Feb 08, 2013 at 04:12 PM
EditorGUILayout is only for custom inspector stuff. You don't want to use that in OnGUI
.
ammmmmmmmmmm Ok what should I do than?
and where can be used EditorGUILayout than?
The whole "UnityEditor" namespace belongs to the Unity editor. You can't include this namespace in classes you will use at runtime / in your game. Those classes can only be used in editor scripts which extend the unity editor. Take a look at Extending the Editor.
@OWiz: btw. OnGUI does also exist in EditorWindows, so your statement can be a bit confusing ;)
Your answer
Follow this Question
Related Questions
targeting desnsity inside buoyancy script 0 Answers
Make String Update for Value (GUI) 1 Answer
How to fix wobbling float when away from spawn? 1 Answer
Extend Unity Player Settings? 0 Answers