Debug.Log Extensions
Documentation (1.1.9)

◆ DrawRay() [2/2]

static void Debug.DrawRay ( Vector3  start,
Vector3  dir,
Color  color,
float  duration = 0f,
bool  depthTest = true 
)
static

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.

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);
}
}
static void DrawRay(Vector3 start, Vector3 dir)
Draws a line from start to start + dir in world coordinates.
Definition: Debug.cs:6844
Extended version of the built-in Debug class with additional methods to ease debugging while developi...
Definition: Debug.cs:34
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?