返回介绍

Debug.DrawRay v

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

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

Parameters 参数

startPoint in world space where the ray should start.
dirDirection and length of the ray.
colorColor of the drawn line.
durationHow long the line will be visible for (in seconds).
depthTestShould the line be obscured by other objects closer to the camera?

Description 描述

Draws a line from start to start + dir in world coordinates.
在世界空间中画条射线,从起点开始向指向的方向延伸。

The duration parameter determines how long the line will be visible after the frame it is drawn. If duration is 0 (the default) then the line is rendered 1 frame.
duration参数决定了在此帧中该射线多长可见。如果duration的值为零(默认为零)该射线被渲染一帧。

If depthTest is set to true then the line will be obscured by other objects in the scene that are nearer to the camera.
如果depthTest被设置为true,那么将会其他场景中物体将会靠近摄像机。

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.
该线将会在编辑器视图中画出。如果游戏视图打开绘画线框,在该视图中该线将会被可见。

JavaScript:

	// Frame update example: Draws a 10 meter long green line from the position for 1 frame.
	function Update () {
		var forward : Vector3 = transform.TransformDirection(Vector3.forward) * 10;
		Debug.DrawRay (transform.position, forward, Color.green);
	}

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.DrawRay(contact.point, contact.normal, Color.green, 2, false);
		}
	}

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    void Update() {
        Vector3 forward = transform.TransformDirection(Vector3.forward) * 10;
        Debug.DrawRay(transform.position, forward, Color.green);
    }
}

C#:

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

debug

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

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

发布评论

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