Legacy Documentation: Version 5.5
LanguageEnglish
  • C#
  • JS

Script language

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

Handles.ScaleSlider

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

Submission failed

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

Close

Cancel

public static function ScaleSlider(scale: float, position: Vector3, direction: Vector3, rotation: Quaternion, size: float, snap: float): float;
public static float ScaleSlider(float scale, Vector3 position, Vector3 direction, Quaternion rotation, float size, float snap);

Parameters

scale The value the user can modify.
position The position of the handle.
direction The direction of the handle.
rotation The rotation of whole object.
size The size of the handle.
snap The new value after the user has modified it.

Returns

float The value modified by the user's interaction with the handle.

Description

Make a directional scale slider.


Scale slider handle in the Scene View.

Note: Use HandleUtility.GetHandleSize if you want the handle to always remain the same size on the screen.

#pragma strict
// Name this script "ScaleSliderEditor"
@CustomEditor(ScaleSlider)
@CanEditMultipleObjects
public class ScaleSliderEditor extends Editor {
	public function OnSceneGUI() {
		var t: ScaleSlider = (target as ScaleSlider);
		EditorGUI.BeginChangeCheck();
		var scale: float = Handles.ScaleSlider(t.scale, Vector3.zero, Vector3.right, Quaternion.identity, 3, 0.5f);
		if (EditorGUI.EndChangeCheck()) {
			Undo.RecordObject(target, "Scale Slider");
			t.scale = scale;
			t.Update();
		}
	}
}
// Name this script "ScaleSliderEditor"
using UnityEngine;
using UnityEditor;

[CustomEditor(typeof(ScaleSlider))] [CanEditMultipleObjects] public class ScaleSliderEditor : Editor { public void OnSceneGUI() { ScaleSlider t = (target as ScaleSlider);

EditorGUI.BeginChangeCheck(); float scale = Handles.ScaleSlider(t.scale, Vector3.zero, Vector3.right, Quaternion.identity,3,0.5f); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Scale Slider"); t.scale = scale; t.Update(); } } }

And attach this script to the GameObject:

#pragma strict
// Name this script "ScaleSlider"
@ExecuteInEditMode
public class ScaleSlider extends MonoBehaviour {
	public var scale: float = 1;
	public function Update() {
		transform.localScale = new Vector3(scale, 1, 1);
	}
}
// Name this script "ScaleSlider"
using UnityEngine;

[ExecuteInEditMode] public class ScaleSlider : MonoBehaviour { public float scale = 1; public void Update() { transform.localScale = new Vector3(scale,1,1); } }