Skip to content

Instantly share code, notes, and snippets.

@marcelschmidtdev
Created March 30, 2016 00:32
Show Gist options
  • Save marcelschmidtdev/4ac2b09e39535d1c716ab92419916836 to your computer and use it in GitHub Desktop.
Save marcelschmidtdev/4ac2b09e39535d1c716ab92419916836 to your computer and use it in GitHub Desktop.
Visualizes vector axes in Unity
using UnityEngine;
using System.Collections;
public class DrawSampleVecs : MonoBehaviour
{
void OnDrawGizmos()
{
Color color;
color = Color.green;
// local up
DrawHelperAtCenter(this.transform.up, color, 2f);
color.g -= 0.5f;
// global up
DrawHelperAtCenter(Vector3.up, color, 1f);
color = Color.blue;
// local forward
DrawHelperAtCenter(this.transform.forward, color, 2f);
color.b -= 0.5f;
// global forward
DrawHelperAtCenter(Vector3.forward, color, 1f);
color = Color.red;
// local right
DrawHelperAtCenter(this.transform.right, color, 2f);
color.r -= 0.5f;
// global right
DrawHelperAtCenter(Vector3.right, color, 1f);
}
private void DrawHelperAtCenter(Vector3 direction, Color color, float scale)
{
Gizmos.color = color;
Vector3 destination = transform.position + direction * scale;
Gizmos.DrawLine(transform.position, destination);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment