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

Parameters

start@param start Точка в мировом пространстве, откуда начнётся луч.
dir@param dir Направление и длина луча.
color@param color Цвет отображаемой линии.
duration@param duration Время отображения линии (в секундах).
depthTest@param depthTest Будет ли линия перекрываться более близкими к камере объетами?

Description

Рисует линию от точки start до точки start + dir в мировых координатах.

duration - сколько (в секундах) линия будет отображаться. При duration равное 0 (по умолчанию) линия будет отображаться один кадр.

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