Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


CalculateLOD(Vector3, float)

Determines the appropriate level of detail for a gizmo in the Scene view at a specified position with a specified radius.
Read time 1 minuteLast updated 10 days ago

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule
public static float CalculateLOD(Vector3 position, float radius)

Parameters

position

The centre of the gizmo in world space.

radius

The maximum extent of the gizmo.

Returns

Type

Description

floatReturns a value between 0 and 1 that represents the level of detail for the gizmo.

Remarks

A return value of 0 indicates the gizmo is not visible. The gizmo might not be visible because it is too small on the screen or because it is outside of the Scene view camera frustum. The return value is quantized to eighths to reduce the number of produced batches. This can be further controlled with the 'Fade Gizmos' options in the Gizmos menu.

Examples

using UnityEngine;public class MyLODedComponent : MonoBehaviour{ // Draw a blue sphere at the transform's position, fading out as it gets further away private void OnDrawGizmos() { float lod = Gizmos.CalculateLOD(transform.position, 1); // Cull any gizmos that are too small or off screen if (lod == 0.0f) return; // Fade the gizmos out so that they don't pop in and out when scrolling around the scene Gizmos.color = Color.blue * lod; Gizmos.DrawSphere(transform.position, 1); }}