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

Parameters

start应作为该直线起始点的世界空间中的点。
end应作为该直线结束点的世界空间中的点。
color该直线的颜色。
duration该直线的可见长度应为多长。
depthTest该直线是否应被靠近此摄像机的对象遮挡?

Description

在指定的起始点与结束点之间绘制一条直线。

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.

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; } } }
using UnityEngine;

public class Example : MonoBehaviour { // Event callback example: Debug-draw all contact points and normals for 2 seconds. void OnCollisionEnter(Collision collision) { foreach (ContactPoint contact in collision.contacts) { Debug.DrawLine(contact.point, contact.point + contact.normal, Color.green, 2, false); } } }