position | Center of the handle in 3D space. |
rotation | Orientation of the handle in 3D space. |
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.
Note: Use HandleUtility.GetHandleSize where you might want to have constant screen-sized handles.
Make a 3D Scene view position handle.
This will behave like the built-in move tool in Unity.
To control the orientation of the handle, set Handles.matrix prior to calling this function.
Make the object look always to the position handle.
To use this example, save this script to the Assets/Editor folder:
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( ); } }
}
...and place this script on the object to wish to edit the LookAt point for:
using UnityEngine;
[ExecuteInEditMode] public class PositionHandle : MonoBehaviour { public Vector3 lookTarget = new Vector3( 0,2,0 );
public void Update( ) { transform.LookAt( lookTarget ); } }