Legacy Documentation: Version 5.0
Language: English
  • C#
  • JS

Script language

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

EditorGUILayout.MinMaxSlider

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public static function MinMaxSlider(minValue: float, maxValue: float, minLimit: float, maxLimit: float, params options: GUILayoutOption[]): void;
public static void MinMaxSlider(float minValue, float maxValue, float minLimit, float maxLimit, params GUILayoutOption[] options);
public static function MinMaxSlider(label: GUIContent, minValue: float, maxValue: float, minLimit: float, maxLimit: float, params options: GUILayoutOption[]): void;
public static void MinMaxSlider(GUIContent label, float minValue, float maxValue, float minLimit, float maxLimit, params GUILayoutOption[] options);

Parameters

labelOptional label in front of the slider.
valueThe value the slider shows. This determines the position of the draggable thumb.
minValueThe lower value of the range the slider shows, passed by reference.
maxValueThe upper value at the range the slider shows, passed by reference.
minLimitThe limit at the left end of the slider.
maxLimitThe limit at the right end of the slider.
optionsAn optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the style.
See Also: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.

Description

Make a special slider the user can use to specify a range between a min and a max.


Moves the selected object randomly betweeen the interval.

	// Place the selected object randomly between the interval of the Min Max Slider
	// in the X,Y,Z coords
	
	class EditorGUILayoutMinMaxSlider extends EditorWindow {
	
		var minVal : float = -10;
		var minLimit : float = -20;
		var maxVal : float = 10;
		var maxLimit : float = 20;
		
		@MenuItem("Examples/Place Object Randomly")
		static function Init() {
			var window = GetWindow(EditorGUILayoutMinMaxSlider);
			window.Show();
		}
		
		function OnGUI() {
			EditorGUILayout.LabelField("Min Val:", minVal.ToString());
			EditorGUILayout.LabelField("Max Val:", maxVal.ToString());
			EditorGUILayout.MinMaxSlider(minVal, maxVal, minLimit, maxLimit);
			if(GUILayout.Button("Move!"))
				PlaceRandomly();
		}
		
		function PlaceRandomly() {
			if(Selection.activeTransform)
				Selection.activeTransform.position = 
					Vector3(Random.Range(minVal, maxVal),
							Random.Range(minVal, maxVal),
							Random.Range(minVal, maxVal));
			else 
				Debug.LogError("Select a GameObject to randomize its position.");
		}
	}