Legacy Documentation: Version 2018.1 (Go to current version)
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.


Suggest a change


Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.


Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.



public static method DrawLine(start: Vector3, end: Vector3, color: Color = Color.white, duration: float = 0.0f, depthTest: bool = true): void;
public static void DrawLine(Vector3 start, Vector3 end, Color color = Color.white, float duration = 0.0f, bool depthTest = true);


startPoint in world space where the line should start.
endPoint in world space where the line should end.
colorColor of the line.
durationHow long the line should be visible for.
depthTestShould the line be obscured by objects closer to the camera?


Draws a line between specified start and end points.

The line will be drawn in the Game view of the editor when the game is running and the gizmo drawing is enabled. The line will also be drawn in the Scene when it is visible in the Game view. Leave the game running and showing the line. Switch to the Scene view and the line will be visible.

The duration is the time (in seconds) for which the line will be visible after it is first displayed. A duration of zero shows the line for just one frame.

Note: This is for debugging playmode only. Editor gizmos should be drawn with Gizmos.Drawline or Handles.DrawLine instead.

// Frame update example: Draws a red line from the world-space origin to the point (1, 0, 0) for 1 frame.
function Update () {
    Debug.DrawLine (Vector3.zero, Vector3 (1, 0, 0), Color.red);
using UnityEngine;

public class ExampleScript : MonoBehaviour { void Start() { // draw a 5-unit white line from the origin for 2.5 seconds Debug.DrawLine(Vector3.zero, new Vector3(5, 0, 0), Color.white, 2.5f); }

private float q = 0.0f;

void FixedUpdate() { // always draw a 5-unit colored line from the origin Color color = new Color(q, q, 1.0f); Debug.DrawLine(Vector3.zero, new Vector3(0, 5, 0), color); q = q + 0.01f;

if (q > 1.0f) { q = 0.0f; } } }
// Event callback example: Debug-draw all contact points and normals for 2 seconds.
function OnCollisionEnter(collision : Collision) {
    for (var contact : ContactPoint in collision.contacts) {
        Debug.DrawLine(contact.point, contact.point + contact.normal, Color.green, 2, false);
no example available in C#

Did you find this page useful? Please give it a rating: