duck

C# Handles.PositionHandle example

Oct 28th, 2015
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. [@ExecuteInEditMode()]
  5. public class LookAtPoint : MonoBehaviour {
  6.  
  7.     // LookAtPoint.cs
  8.     // This Script has to be outside of the editor folder.
  9.     //
  10.     // Usage: Just Place this script on the object you want to work the handle with.
  11.     public Vector3 lookAtPoint = Vector3.zero;
  12.    
  13.     void Update () {
  14.         transform.LookAt (lookAtPoint);
  15.     }
  16. }
  17.  
  18. ____________________________________________________________
  19.  
  20. using UnityEngine;
  21. using UnityEditor;
  22.  
  23. [@CustomEditor (typeof(LookAtPoint))]
  24. class LookAtPointEditor : Editor {
  25.     void OnSceneGUI () {
  26.         LookAtPoint look = (LookAtPoint) target;
  27.         look.lookAtPoint = Handles.PositionHandle (look.lookAtPoint, Quaternion.identity);
  28.         if (GUI.changed)
  29.         {
  30.             EditorUtility.SetDirty (target);
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment