Gizmos部分讲解
Gizmos.color
这里可以设置可视化边界的颜色。如:
Gizmos.color= Color.red;
可设置边界为红色。
Gizmos.DrawCube
public static void DrawCube(Vector3 center, Vector3 size);
第一个参数需要给一个坐标,第二个参数需要设置描绘的长方体的长、宽、高的大小及比例。如:
// private void OnDrawGizmosSelected() {
Gizmos.color = Color.red;
Gizmos.DrawCube(transform.position,new Vector3(5,1,5));
}
效果:
Gizmos.DrawFrustum
public static void DrawFrustum(Vector3 center, float fov, float maxRange, float minRange, float aspect);
float fov:垂直视野
float maxRange:截头远平面的距离
float minRange:截头近平面的距离
float aspect:宽高比
这主要用于绘制相机可视区域。
Gizmos.DrawGUITexture
public static void DrawGUITexture(Rect screenRect, Texture texture, int leftBorder, int rightBorder, int topBorder, int bottomBorder, Material mat = null);
// public Texture myTexture;
private void OnDrawGizmosSelected() {
Gizmos.color = Color.red;
Gizmos.DrawGUITexture(new Rect(5,5,10,10),myTexture);
}
Gizmos.DrawWireSphere
public static void DrawWireSphere(Vector3 center, float radius);
这里可以描绘一个圆,第一个参数是设置圆中心的位置,第二个参数是设置圆的半径。如:
通过Gizmos.DrawWieeSphere检测范围中的物体
// //设置一个碰撞器的数组
Collider[] cols;
//数组的成员为Center范围内的碰撞器
cols=Physics.OverlapSphere(Center.transform.position, audRange);
//遍历数组成员,寻找是否含有玩家
foreach (Collider col in cols) { if (col.tag == "Player") { return true; } }
Center.transform.position应该和DrawWireSphere设置的中心相等, audRange应该与DrawWieeSphere设置的半径相等,这样就可以检测范围中的物体。