Skip to content

Instantly share code, notes, and snippets.

@Naphier
Last active November 5, 2015 01:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Naphier/adfe9341241453aefcff to your computer and use it in GitHub Desktop.
Save Naphier/adfe9341241453aefcff to your computer and use it in GitHub Desktop.
using UnityEngine;
// Displays lines for the Local Axis of a game object evenwhen the object is not selected.
public class ShowLocalAxis : MonoBehaviour
{
// This is used by the CustomTransformComponent class
// and the custom inspector for this class so that we can tag the script component
// for deletion at the proper time. We're hiding it in the inspector since it shouldn't
// be modified by the user, but needs to be publically accessible by other classes.
[HideInInspector]
public bool destroyWhenSafe = false;
// This is the length of the lines to be displayed.
// I've set a range here to prevent them from being overly long or too short.
// The range tag will make the inspector draw a slider for the value instead of a field box.
[Range(1f,100f)]
public float handleLength = 10f;
// This method is run by Unity when gizmos should be drawn in the Scene view.
public void OnDrawGizmos()
{
// First we need to set the gizmo matrix from the transform's local values.
Gizmos.matrix = transform.localToWorldMatrix;
Gizmos.color = Color.blue; // We define the gizmo color before each line.
Gizmos.DrawLine(Vector3.zero, Vector3.forward * handleLength); // Then we draw the line along the axis.
Gizmos.color = Color.red;
Gizmos.DrawLine(Vector3.zero, Vector3.right * handleLength);
Gizmos.color = Color.yellow;
Gizmos.DrawLine(Vector3.zero, Vector3.up* handleLength);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment