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.MinMaxSlider

static function MinMaxSlider(label: GUIContent, position: Rect, minValue: float, maxValue: float, minLimit: float, maxLimit: float): void;
static void MinMaxSlider(GUIContent label, Rect position, float minValue, float maxValue, float minLimit, float maxLimit);
static def MinMaxSlider(label as GUIContent, position as Rect, minValue as float, maxValue as float, minLimit as float, maxLimit as float) as void
static function MinMaxSlider(position: Rect, minValue: float, maxValue: float, minLimit: float, maxLimit: float): void;
static void MinMaxSlider(Rect position, float minValue, float maxValue, float minLimit, float maxLimit);
static def MinMaxSlider(position as Rect, minValue as float, maxValue as float, minLimit as float, maxLimit as float) as void

Parameters

labelOptional label in front of the slider.
positionRectangle on the screen to use for 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.

Description

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


MinMax Slider in an Editor Window.

	// Place the selected object randomly between the interval of the Min Max Slider
	// in the X,Y,Z coords
	
	class EditorGUIMinMaxSlider extends EditorWindow {
	
		var minVal : float = -10;
		var minLimit : float = -20;
		var maxVal : float = 10;
		var maxLimit : float = 20;
		
		@MenuItem("Examples/Editor GUI Move Object Randomly")
		static function Init() {
			var window = GetWindow(EditorGUIMinMaxSlider);
			window.Show();
		}
		
		function OnGUI() {
			EditorGUI.MinMaxSlider(
				GUIContent("Random range:"), 
				Rect(0,0,position.width,20),
				minVal, maxVal,
				minLimit, maxLimit);
			if(GUI.Button(Rect(0,25,position.width, position.height -25),"Randomize!"))
				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.");
		}
	}