- Home /
How Do I Draw the Bounding Sphere in Screen Space?
I've searched high and low and can't find the answer to this question.
I can draw the bounding sphere in world space, but it will not render to screen space in the Scene view. Help is much appreciated.
Example:
void OnDrawGizmosSelected(){
Gizmos.color = Color.white;
Gizmos.DrawSphere(Camera.current.WorldToViewportPoint(gameobject.transform.position),1f);
}
Gizmos are drawn only when the object is selected. Do you Selected it?
Yes. It seems the sphere doesn't want to draw in screen coordinates.
Is it possible then just to get the radius in screen space?
What exactly do you want to accomplish? What do you mean "in screen space", in your case? Do you attach your script to a screen space object, a GUITexture, ...? Your current approach computes viewport coordinates, but DrawSphere() expects world coordinates.
I want to find the screenspace bounding sphere's radius of a mesh, then compare it to a value. If that radius is less than or equal to this value, disable the mesh renderer component.
Answer by tomka · May 25, 2012 at 07:37 AM
Don't convert to Viewport coordinates.
void OnDrawGizmosSelected(){
Gizmos.color = Color.white;
Gizmos.DrawSphere(gameobject.transform.position,1f);
}
Also, enable gizmos.
This is not the answer as I want a sphere to be drawn in screenspace.