Version: 2021.3
言語: 日本語
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); } }