Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

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

Debug.DrawLine

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

Parameters

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?

Description

Draws a line between specified start and end points.

The line will be drawn in the scene view of the editor. If gizmo drawing is enabled in the game view, the line will also be drawn there. 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;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void Update() {
        Debug.DrawLine(Vector3.zero, new Vector3(1, 0, 0), Color.red);
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	def Update() as void:
		Debug.DrawLine(Vector3.zero, Vector3(1, 0, 0), Color.red)

	// 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);
		}
	}
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void OnCollisionEnter(Collision collision) {
        foreach (ContactPoint contact in collision.contacts) {
            Debug.DrawLine(contact.point, contact.point + contact.normal, Color.green, 2, false);
        }
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	def OnCollisionEnter(collision as Collision) as void:
		for contact as ContactPoint in collision.contacts:
			Debug.DrawLine(contact.point, (contact.point + contact.normal), Color.green, 2, false)