Skip to content

Instantly share code, notes, and snippets.

@smkplus
Created January 8, 2020 17:13
Show Gist options
  • Save smkplus/ad7c6e331f1255c5618814ad022fba71 to your computer and use it in GitHub Desktop.
Save smkplus/ad7c6e331f1255c5618814ad022fba71 to your computer and use it in GitHub Desktop.
DirectionGizmos
using UnityEditor;
using UnityEngine;

public class DirectionGizmos : MonoBehaviour
{
    public Transform target;
    public Color color = Color.red;
    public float thickness = 2;

    private void OnDrawGizmos()
    {
        if (target == null) return;
        
        Handles.color = color;
        Handles.DrawAAPolyLine(EditorGUIUtility.whiteTexture, thickness, transform.position, this.target.transform.position);
            
        Handles.color = color;
            
        Handles.ConeHandleCap(
            0,
            target.position,
            Quaternion.LookRotation(target.position - transform.position),
            0.2f,
            EventType.Repaint
        );
            
        Handles.SphereHandleCap(
            0,
            transform.position,
            transform.rotation * Quaternion.LookRotation(Vector3.right),
            0.2f,
            EventType.Repaint
        );
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment