Debug.DrawLine 绘制线
static function DrawLine (start : Vector3, end : Vector3, color : Color = Color.white, duration : float = 0.0f) : void
Description描述
Draws a line from the point start to end with color for a duration of time. If duration is 0 then the line is rendered 1 frame.
从start起点到end末点,经过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.
这条线将绘制在编辑器的场景视图,如果在游戏视图Gizmos被打开,那么线也会显示在游戏窗口。
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
void Update() {
Debug.DrawLine(Vector3.zero, new Vector3(1, 0, 0), Color.red);
}
}
// Frame update example: Draws a red line from the world-space origin to the point (1, 0, 0) for 1 frame.
//帧更新例子:绘制一条红线从世界坐标原点到点(1, 0, 0),这会用1帧渲染出来。
function Update () {
Debug.DrawLine (Vector3.zero, Vector3 (1, 0, 0), Color.red);
}
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
void OnCollisionEnter(Collision collision) {
foreach (ContactPoint contact in collision.contacts) {
Debug.DrawLine(contact.point, 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.DrawLine(contact.point, contact.point + contact.normal, Color.green, 2);
}
}
最后修改:2011年9月16日 Friday 13:11