Debug.DrawRay 绘制射线

static function DrawRay (start : Vector3, color : Color = Color.white, duration : float = 0.0f) : void

Description描述

Draws a line from start to start + dir with color for a duration of time. If duration is 0 then the line is rendered 1 frame.

从start起始位置到start+dir,经过duration一段时间,绘制一条color颜色的线。如果duration为0,那么这条线在1帧中被渲染。

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.

这条线将绘制在编辑器的场景视图。如果gizmo在游戏视图中被启用,这条线也在游戏视图中绘制。

using UnityEngine;

using System.Collections;



public class example : MonoBehaviour {

	void Update() {

		Vector3.forward) * 10;

		Debug.DrawRay(transform.position, forward, Color.green);

	}

}
// Frame update example: Draws a 10 meter long green line from the position for 1 frame.

//帧更新例子:从该位置绘制一条10米长绿色的线,这将在1帧中渲染。

function Update () {

	var forward : Vector3.forward) * 10;

	Debug.DrawRay (transform.position, forward, Color.green);

}
using UnityEngine;

using System.Collections;



public class example : MonoBehaviour {

	void OnCollisionEnter(Collision collision) {

		foreach (ContactPoint contact in collision.contacts) {

			Debug.DrawRay(contact.point, contact.normal, Color.green, 2);

		}

	}

}
// Event callback example: Debug-draw all contact points and normals for 2 seconds.

//事件回调例子:绘制所有接触点和法线,这将用2秒时间渲染

function OnCollisionEnter(collision : Collision) {

	for (var contact : ContactPoint in collision.contacts) {

		Debug.DrawRay(contact.point, contact.normal, Color.green, 2);

	}

}
Page last updated: 2011-9-16