我想使用脚本创建一个圆锥形的Gizmo,如下图所示。
void OnDrawGizmosSelected()
{
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(transform.position, range);
}
有人可以帮忙吗?
答案 0 :(得分:0)
下面的代码是Tetrad对similar question的回答的修改版本。
void OnDrawGizmosSelected()
{
float angle = 30.0f;
float rayRange = 10.0f;
float halfFOV = angle / 2.0f;
float coneDirection = 180;
Quaternion upRayRotation = Quaternion.AngleAxis(-halfFOV + coneDirection, Vector3.forward);
Quaternion downRayRotation = Quaternion.AngleAxis(halfFOV + coneDirection, Vector3.forward);
Vector3 upRayDirection = upRayRotation * transform.right * rayRange;
Vector3 downRayDirection = downRayRotation * transform.right * rayRange;
Gizmos.DrawRay(transform.position, upRayDirection);
Gizmos.DrawRay(transform.position, downRayDirection);
Gizmos.DrawLine(transform.position + downRayDirection, transform.position + upRayDirection);
}
希望有帮助!