Version: 2019.4
public static void DrawRay (Vector3 start, Vector3 dir, Color color= Color.white, float duration= 0.0f, bool depthTest= true);

パラメーター

startレイを開始する位置(ワールド座標)
dirレイの向きと長さ
colorラインの色
durationラインを表示する時間(秒単位)
depthTestラインがカメラから近いオブジェクトによって隠された場合にラインを隠すかどうか

説明

ワールド座標にて start (開始地点)から start + dir (開始地点+方向)までラインを描画します。

duration は命令を発行してからラインが描画され、消えるまでの時間(秒単位)です。duration が 0 の場合は 1 フレームのみ表示されます。

If depthTest is set to true then the line will be obscured by other objects in the Scene that are nearer to the camera.

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.

using UnityEngine;

public class Example : MonoBehaviour { // Frame update example: Draws a 10 meter long green line from the position for 1 frame. void Update() { Vector3 forward = transform.TransformDirection(Vector3.forward) * 10; Debug.DrawRay(transform.position, forward, Color.green); } }
using UnityEngine;

public class Example : MonoBehaviour { // Event callback example: Debug-draw all contact points and normals for 2 seconds. void OnCollisionEnter(Collision collision) { Debug.DrawRay(collision.contacts[0].point, collision.contacts[0].normal, Color.green, 2, false); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961