EKsumic's Blog

let today = new Beginning();

Click the left button to use the catalog.

OR

[Unity]Debug.DrawLine()是什么?如何使用?

Debug.DrawLine()是在场景视图中可视化地面检查光线的工具。

 

Debug.DrawLine()方法有2个参数,

DrawLine(起始坐标,结束坐标)

 

关于Unity官方插件中的ThirdPersonCharacter.cs中的这一句:

Debug.DrawLine(transform.position + (Vector3.up * 0.1f), transform.position + (Vector3.up * 0.1f) + (Vector3.down * m_GroundCheckDistance));

 

在Scene中的实际效果是这样的:

白线样例

 

注释掉这段代码,是这样的:

S2

 

然后我们来分析这段代码,

第一个参数——transform.position + (Vector3.up * 0.1f)

第二个参数——transform.position + (Vector3.up * 0.1f) + (Vector3.down * m_GroundCheckDistance)

 

第一个参数——(0,0,0)+(0,1,0)*0.1f

第二个参数——(0,0,0)+(0,1,0)*0.1f+(0,-1,0)*0.1f

 

不理解Vector3.up为什么是(0,1,0)点击→这里

 

 

参考文档:

[1] Unity Documentation-Scripting API : Debug.DrawLine

This article was last edited at 2020-04-05 03:32:40

* *