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

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 PositionHandle(position: Vector3, rotation: Quaternion): Vector3;
public static Vector3 PositionHandle(Vector3 position, Quaternion rotation);

Parameters

position Center of the handle in 3D space.
rotation Orientation of the handle in 3D space.

Returns

Vector3 The new value modified by the user's interaction with the handle. If the user has not moved the handle, it returns the same value that you passed into the function.

Description

Make a 3D Scene view position handle.

This behaves like the built-in Move tool in Unity.

To control the orientation of the handle, set Handles.matrix before calling this function.




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

To use this example, save this script to the Assets/Editor folder:

#pragma strict
@CustomEditor(PositionHandle)
public class PositionHandleEditor extends Editor {
	function OnSceneGUI() {
		var t: PositionHandle = target as PositionHandle;
		// Set the colour of the next handle to be drawn
		Handles.color = Color.magenta;
		EditorGUI.BeginChangeCheck();
		var lookTarget: Vector3 = Handles.PositionHandle(t.lookTarget, Quaternion.identity);
		if (EditorGUI.EndChangeCheck()) {
			Undo.RecordObject(target, "Changed Look Target");
			t.lookTarget = lookTarget;
			t.Update();
		}
	}
}
using UnityEngine;
using UnityEditor;

[CustomEditor( typeof( PositionHandle ) )] public class PositionHandleEditor : Editor { void OnSceneGUI( ) { PositionHandle t = target as PositionHandle;

// Set the colour of the next handle to be drawn Handles.color = Color.magenta;

EditorGUI.BeginChangeCheck( ); Vector3 lookTarget = Handles.PositionHandle( t.lookTarget, Quaternion.identity );

if( EditorGUI.EndChangeCheck( ) ) { Undo.RecordObject( target, "Changed Look Target" ); t.lookTarget = lookTarget; t.Update( ); } } }

Then, place this script on the GameObject you want to edit the LookAt point for:

#pragma strict
@ExecuteInEditMode
public class PositionHandle extends MonoBehaviour {
	public var lookTarget: Vector3 = new Vector3(0, 2, 0);
	public function Update() {
		// Make the object always face the position handle
		transform.LookAt(lookTarget);
	}
}
using UnityEngine;

[ExecuteInEditMode] public class PositionHandle : MonoBehaviour { public Vector3 lookTarget = new Vector3( 0,2,0 );

public void Update( ) { // Make the object always face the position handle transform.LookAt( lookTarget ); } }