返回介绍

Debug.DrawLine 画线

发布于 2019-12-18 15:37:39 字数 3012 浏览 1656 评论 0 收藏 0

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

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.
该线条将会显示在编辑器窗口的场景中。如果在游戏视窗打开绘画线框,该线条也会被画在该视图。在可持续的时间内(以秒为单位)该线将在第一次显示后可见。duration值为0表示该线仅显示一帧可见。

Note: This is for debugging playmode only. Editor gizmos should be drawn with Gizmos.Drawline or Handles.DrawLine instead.
注意:这仅供调试。编辑线框用Gizmos.Drawline或 Handles.DrawLine代替该方法。

JavaScript:

	// 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);
	}

JavaScript:

// 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);
		}
	}

C#:

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

C#:

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);
        }
    }
}

debug

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文