Version: 5.6 (switch to 2017.1b)
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 will return the same value as you passed into the function.

Description

Make a position handle.

This handle behaves like the built-in move tool in Unity.


Position handle in the Scene View.''

Add the following script to your Assets folder as PositionHandleExample.cs and add the PositionHandleExample component to an object in a scene.

#pragma strict
@ExecuteInEditMode
public class PositionHandleExample extends MonoBehaviour {
	Vector3targetPosition {
		return m_TargetPosition;
	}
	 {
		m_TargetPosition = value;
	}
	@SerializeField
	private var m_TargetPosition: Vector3 = new Vector3(1f, 0f, 2f);
	public virtual function Update() {
		transform.LookAt(m_TargetPosition);
	}
}
using UnityEngine;

[ExecuteInEditMode] public class PositionHandleExample : MonoBehaviour { public Vector3 targetPosition { get { return m_TargetPosition; } set { m_TargetPosition = value; } } [SerializeField] private Vector3 m_TargetPosition = new Vector3(1f, 0f, 2f);

public virtual void Update() { transform.LookAt(m_TargetPosition); } }

Add the following script to Assets/Editor as PositionHandleExampleEditor.cs and select the object with the PositionHandleExample component.

#pragma strict
@CustomEditor(PositionHandleExample)
@CanEditMultipleObjects
public class PositionHandleExampleEditor extends Editor {
	protected virtual function OnSceneGUI() {
		var example: PositionHandleExample = PositionHandleExampletarget;
		EditorGUI.BeginChangeCheck();
		var newTargetPosition: Vector3 = Handles.PositionHandle(example.targetPosition, Quaternion.identity);
		if (EditorGUI.EndChangeCheck()) {
			Undo.RecordObject(example, "Change Look At Target Position");
			example.targetPosition = newTargetPosition;
			example.Update();
		}
	}
}
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(PositionHandleExample)), CanEditMultipleObjects] public class PositionHandleExampleEditor : Editor { protected virtual void OnSceneGUI() { PositionHandleExample example = (PositionHandleExample)target;

EditorGUI.BeginChangeCheck(); Vector3 newTargetPosition = Handles.PositionHandle(example.targetPosition, Quaternion.identity); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(example, "Change Look At Target Position"); example.targetPosition = newTargetPosition; example.Update(); } } }