Select your preferred scripting language. All code snippets will be displayed in this language.
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.
CloseFor 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.
Closestart | Point in world space where the line should start. |
end | Point in world space where the line should end. |
color | Color of the line. |
duration | How long the line should be visible for. |
depthTest | Should 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 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); } }
// 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); } } }
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information