可以通过调整Gizmos.matrix来实现。下面一段代码展示了临时让Gizmos画出的WireCube和立方体在位置和角度都重合的方法。 varmatrix=Gizmos.matrix;Colorcolor=Gizmos.color;Gizmos.color=Color.yellow;Gizmos.matrix=transform.localToWorldMatrix;//这里的m_localCenter是本地坐标系下的中心坐标Gizmos.DrawWireCube(m_local...
Gizmos.DrawLine(farTopLeft, farTopRight); Gizmos.DrawLine(farTopRight, farBottomRight); Gizmos.DrawLine(farBottomRight, farBottomLeft); Gizmos.DrawLine(farBottomLeft, farTopLeft); Gizmos.DrawLine(nearTopLeft, farTopLeft); Gizmos.DrawLine(nearTopRight, farTopRight); Gizmos.DrawLine(nearBottom...
旋转的处理,核心是Quaternion.FromToRotation方法。 一般的,假设我们的线段方向是(1,0,1),想把模型的x正轴对齐线段,那么这个旋转量就是: var quaternion = Quaternion.FromToRotation(Vector3.right, new Vector3(1, 0, 1)); 为什么使用【Vector3.right】进行旋转量计算而非具体的某个【GameObject.transform...
voidOnDrawGizmos() { Gizmos.color = contact ? Color.cyan : Color.yellow; Gizmos.DrawWireSphere(transform.position, radius); } } 然后就完了。运行项目并且打开场景。将Player往墙体的边缘慢慢拖过去。你可以看到墙体在反推,让Player总是停留在边缘。那么这里做了什么呢? Physics.OverlapSphere返回了与球体发...
Function OnDrawGizmosSelected(){ //在变换位置处绘制一个黄色立方体 Gizmos.color = Color.yellow; Gizmos.DrawWireCube (transtorm.position, Vector3(1,1,1)); } ◆ Static function DrawWireSphere(center:Vector3,radius:float):void 描述:用center和radius绘制一个线框球体. ...
DrawSolidDisc DrawSolidArc DrawSolidRectangleWithOutline 4.1.6 绘制圆弧: DrawWireDisc 、 DrawWireArc 、 DrawWireCube ●DrawWireDisc:在 3D 空间中绘制扁平圆盘的轮廓。 ●DrawWireArc:在 3D 空间中绘制圆弧。 ●DrawWireCube:使用 center 和 size 绘制一个线框盒体。
{voidOnDrawGizmos() {//每帧调用//绘制一个cube边框Gizmos.color =Color.black; Gizmos.DrawWireCube(GetComponent<Renderer>().bounds.center, GetComponent<Renderer>().bounds.size);//绘制一条直线,指向物体正上方Gizmos.color =Color.yellow; Gizmos.DrawLine(transform.position, transform.position+ transform...
color; //centerTrans为碰撞盒的中心点位置,size为碰撞盒的大小 //之所以这么麻烦,是因为unity API没有直接画有旋转长方体的接口 Gizmos.matrix=centerTrans.localToWorldMatrix; Gizmos.color = Color.green; Gizmos.DrawWireCube(Vector3.zero, size); Gizmos.matrix = matrix; Gizmos.color = color; }...
Gizmos.DrawWireCube(boxCollider.center, boxCollider.size); } void OnDrawGizmos() { DrawGizmosOnRunTime(Color.red); } 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 4.2方法二 /// 绘制boxCollider的绿色方框 /// /// ///...
public class CustomCube : MonoBehaviour { void OnDrawGizmos() { //每帧调用 //绘制一个cube边框 Gizmos.color = Color.black; Gizmos.DrawWireCube(GetComponent<Renderer>().bounds.center, GetComponent<Renderer>().bounds.size); //绘制一条直线,指向物体正上方 ...