Legacy Documentation: Version 4.6(go to latest)
Language: English
  • C#
  • JS
  • Boo

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

Sumbission failed

For some reason your suggested change could not be submitted. Please try again 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);
public static def PositionHandle(position as Vector3, rotation as Quaternion) as Vector3

Parameters

position Center of the handle in 3D space.

Returns

Vector3 The new position. If the user has not performed any operation, it will return the same value as you passed it in postion.

Note: Use HandleUtility.GetHandleSize where you might want to have constant screen-sized handles.

Description

Make a 3D Scene view position handle.

This will behave like the built-in move tool in Unity. If you have assigned something to Undo.SetSnapshotTarget, it will work fully with Undo. If you have assigned a non-null value to ignoreRaycastObjects, the center handle will support full raycast placement. To control the orientation of the handle, set Handles.matrix prior to calling this function.


Make the object look always to the position handle.

	//Create a position handle that always looks at "lookAtPoint" in LookAtPoint.js
	
	
	@CustomEditor (LookAtPoint)
	class PositionHandleJS extends Editor {
		function OnSceneGUI () {
		target.lookAtPoint = 
			Handles.PositionHandle (target.lookAtPoint, Quaternion.identity);
		if (GUI.changed)
			EditorUtility.SetDirty (target);
		}
	}

And the Script attached to this handle:

	// LookAtPoint.js
	// This Script has to be outside of the editor folder.
	//
	// Usage: Just Place this script on the object you want to work the handle with.
	
	@script ExecuteInEditMode()
	
	var lookAtPoint = Vector3.zero;
	
	function Update () {
	    transform.LookAt (lookAtPoint);
	}