Custom Unity Line Renderer for drawing gizmo style lines in Unity including play mode. Implemented during this video: https://youtu.be/s926MfazI50
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
// Recommended to attach this script to the Main Camera instance. | |
// Will not render in play mode if not attached to Camera. | |
[ExecuteInEditMode] | |
public class FlowLines : MonoBehaviour | |
{ | |
public Color baseColor; | |
public Material material; | |
public Transform origin; | |
public Vector3[] points; | |
public Color[] colors; | |
void OnPostRender() | |
{ | |
RenderLines(points, colors); | |
} | |
void OnDrawGizmos() | |
{ | |
RenderLines(points, colors); | |
} | |
void RenderLines(Vector3[] points, Color[] colors) | |
{ | |
if (!ValidateInput(points, colors)) | |
{ | |
return; | |
} | |
GL.Begin(GL.LINES); | |
material.SetPass(0); | |
for (int i = 0; i < points.Length; i++) | |
{ | |
GL.Color(baseColor); | |
GL.Vertex(origin.position); | |
GL.Color(colors[i]); | |
GL.Vertex(points[i]); | |
} | |
GL.End(); | |
} | |
private bool ValidateInput(Vector3[] points, Color[] colors) | |
{ | |
return points != null && colors != null && points.Length == colors.Length; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You haven't defined origin, but did in your video