Version: 2018.1
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.

ラインはエディターのシーンビューに描画されます。もしゲームビューのギズモの描画が有効になっている場合はゲームビューにも描画されるようになります。

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