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

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 ScaleHandle(scale: Vector3, position: Vector3, rotation: Quaternion, size: float): Vector3;
public static Vector3 ScaleHandle(Vector3 scale, Vector3 position, Quaternion rotation, float size);

Parameters

scale Scale to modify.
position The position of the handle.
rotation The rotation of the handle.
size Allows you to scale the size of the handle on-scren.

Returns

Vector3 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 Scene view scale handle.

This behaves like the built-in Scale tool.


Scale handle that will appear whenever you select the GameObject.

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

#pragma strict
// Name this script "ScaleAtPointEditor"
@CustomEditor(ScaleAtPoint)
@CanEditMultipleObjects
public class ScaleAtPointEditor extends Editor {
	public function OnSceneGUI() {
		var t: ScaleAtPoint = (target as ScaleAtPoint);
		EditorGUI.BeginChangeCheck();
		var scale: Vector3 = Handles.ScaleHandle(t.scale, Vector3.zero, Quaternion.identity, 1);
		if (EditorGUI.EndChangeCheck()) {
			Undo.RecordObject(target, "Scaled ScaleAt Point");
			t.scale = scale;
			t.Update();
		}
	}
}
// Name this script "ScaleAtPointEditor"
using UnityEngine;
using UnityEditor;

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

EditorGUI.BeginChangeCheck(); Vector3 scale = Handles.ScaleHandle(t.scale, Vector3.zero, Quaternion.identity, 1); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Scaled ScaleAt Point"); t.scale = scale; t.Update(); } } }

And attach this script to the GameObject:

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

[ExecuteInEditMode] public class ScaleAtPoint : MonoBehaviour { public Vector3 scale = Vector3.one; public void Update() { transform.localScale = scale; } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961