Version: 5.5 (switch to 5.6b)
LanguageEnglish
  • C#
  • JS

Script language

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

Handles.ScaleValueHandle

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 ScaleValueHandle(value: float, position: Vector3, rotation: Quaternion, size: float, capFunc: Handles.DrawCapFunction, snap: float): float;
public static float ScaleValueHandle(float value, Vector3 position, Quaternion rotation, float size, Handles.DrawCapFunction capFunc, float snap);

Parameters

value The value the user can modify.
position The position of the handle.
rotation The rotation of the handle.
size The size of the handle.
capFunc The function to use for drawing the handle (e.g. Handles.RectangleCap).
snap The new value after the user has modified it.

Returns

float The new value modified by the user's interaction with the handle. If the user has not moved the handle, it will return the same value as you passed into the function.

Description

Make a single-float draggable handle.

This is used to make the center scale handle. The user can click and drag to scale a single float up and down.


Scale Value handle in the Scene view with an arrow cap as the handle.

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

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

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

EditorGUI.BeginChangeCheck(); float scale = Handles.ScaleValueHandle(t.scale, Vector3.zero, Quaternion.identity,3,Handles.CircleCap,.5f); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Scale Value"); t.scale = scale; t.Update(); } } }

And attach this script to the Handle:

#pragma strict
// Name this script "ScaleValue"
@ExecuteInEditMode
public class ScaleValue extends MonoBehaviour {
	public var scale: float = 0.5f;
	public function Update() {
		GetComponent.<Renderer>().sharedMaterial.color = Color.Lerp(Color.red, Color.green, scale);
	}
}
// Name this script "ScaleValue"
using UnityEngine;

[ExecuteInEditMode] public class ScaleValue : MonoBehaviour { public float scale = 0.5f; public void Update() { GetComponent<Renderer>().sharedMaterial.color = Color.Lerp(Color.red, Color.green, scale); } }