Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

EditorGUI.FloatField

static function FloatField(position: Rect, value: float, style: GUIStyle = EditorStyles.numberField): float;
static float FloatField(Rect position, float value, GUIStyle style = EditorStyles.numberField);
static def FloatField(position as Rect, value as float, style as GUIStyle = EditorStyles.numberField) as float
static function FloatField(position: Rect, label: string, value: float, style: GUIStyle = EditorStyles.numberField): float;
static float FloatField(Rect position, string label, float value, GUIStyle style = EditorStyles.numberField);
static def FloatField(position as Rect, label as string, value as float, style as GUIStyle = EditorStyles.numberField) as float
static function FloatField(position: Rect, label: GUIContent, value: float, style: GUIStyle = EditorStyles.numberField): float;
static float FloatField(Rect position, GUIContent label, float value, GUIStyle style = EditorStyles.numberField);
static def FloatField(position as Rect, label as GUIContent, value as float, style as GUIStyle = EditorStyles.numberField) as float

Parameters

positionRectangle on the screen to use for the float field.
labelOptional label to display in front of the float field.
valueThe value to edit.
styleOptional GUIStyle.

Returns

float The value entered by the user.

Description

Make a text field for entering floats.


Float Field in an Editor Window.

	// Editor Script that multiplies the scale of the current selected GameObject 
	
	class EditorGUIFloatField extends EditorWindow {
	
		var sizeMultiplier : float = 1;
		
		@MenuItem("Examples/Scale selected Object")
		static function Init() {
			var window = GetWindow(EditorGUIFloatField);
			window.position = Rect(0, 0, 210, 30);
			window.Show();
		}
		
		function OnGUI() {
			sizeMultiplier = EditorGUI.FloatField(Rect(3,3,150, 20),
						"Increase scale by:", 
						sizeMultiplier);
			if(GUI.Button(Rect(160,3,45,20), "Scale!"))
				Selection.activeTransform.localScale = 
					Selection.activeTransform.localScale * sizeMultiplier;
		}
	}