Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

SetLODS(scriptingLODs: LOD[]): void;
void SetLODS(LOD[] scriptingLODs);
def SetLODS(scriptingLODs as LOD[]) as void

Parameters

scriptingLODsThe LODs to use for this group.

Description

Set the LODs for the LOD group. This will remove any existing LODs configured on the LODGroup.

	// Programmatically create a LOD group and add LOD levels. 
	// Create a GUI that allows for forcing a specific LOD level.
	var group : LODGroup;

// Use this for initialization function Start () { group = gameObject.AddComponent(LODGroup); // Add 4 LOD levels var lods = new LOD[4];

for (var i = 0; i < 4; i++) { var primType = PrimitiveType.Cube; switch (i) { case 1: primType = PrimitiveType.Capsule; break; case 2: primType = PrimitiveType.Sphere; break; case 3: primType = PrimitiveType.Cylinder; break; } var go = GameObject.CreatePrimitive(primType); go.transform.parent = gameObject.transform;

var renderers = new Renderer[1]; renderers[0] = go.renderer; lods[i] = LOD (1.0 / (i+1), renderers); } group.SetLODS(lods); group.RecalculateBounds (); }

function OnGUI() { if (GUILayout.Button ("Enable / Disable")) group.enabled = !group.enabled; if (GUILayout.Button ("Default")) group.ForceLOD (-1); if (GUILayout.Button ("Force 0")) group.ForceLOD (0); if (GUILayout.Button ("Force 1")) group.ForceLOD (1); if (GUILayout.Button ("Force 2")) group.ForceLOD (2); if (GUILayout.Button ("Force 3")) group.ForceLOD (3); if (GUILayout.Button ("Force 4")) group.ForceLOD (4); if (GUILayout.Button ("Force 5")) group.ForceLOD (5); if (GUILayout.Button ("Force 6")) group.ForceLOD (6); }

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public LODGroup group;
    void Start() {
        group = gameObject.AddComponent<LODGroup>();
        LOD[] lods = new LOD[4];
        int i = 0;
        while (i < 4) {
            PrimitiveType primType = PrimitiveType.Cube;
i1            primType = PrimitiveType.Capsule;
2            primType = PrimitiveType.Sphere;
3            primType = PrimitiveType.Cylinder;
            GameObject go = GameObject.CreatePrimitive(primType);
            go.transform.parent = gameObject.transform;
            Renderer[] renderers = new Renderer[1];
            renderers[0] = go.renderer;
            lods[i] = new LOD(1.0F / (i + 1), renderers);
            i++;
        }
        group.SetLODS(lods);
        group.RecalculateBounds();
    }
    void OnGUI() {
        if (GUILayout.Button("Enable / Disable"))
            group.enabled = !group.enabled;
        
        if (GUILayout.Button("Default"))
            group.ForceLOD(-1);
        
        if (GUILayout.Button("Force 0"))
            group.ForceLOD(0);
        
        if (GUILayout.Button("Force 1"))
            group.ForceLOD(1);
        
        if (GUILayout.Button("Force 2"))
            group.ForceLOD(2);
        
        if (GUILayout.Button("Force 3"))
            group.ForceLOD(3);
        
        if (GUILayout.Button("Force 4"))
            group.ForceLOD(4);
        
        if (GUILayout.Button("Force 5"))
            group.ForceLOD(5);
        
        if (GUILayout.Button("Force 6"))
            group.ForceLOD(6);
        
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	public group as LODGroup

	def Start() as void:
		group = gameObject.AddComponent[of LODGroup]()
		lods as (LOD) = array[of LOD](4)
		i as int = 0
		while i < 4:
			primType as PrimitiveType = PrimitiveType.Cube
			UnityScript.Macros.Switch i:
				case 1:
					primType = PrimitiveType.Capsule
					break 
				case 2:
					primType = PrimitiveType.Sphere
					break 
				case 3:
					primType = PrimitiveType.Cylinder
					break 
			go as GameObject = GameObject.CreatePrimitive(primType)
			go.transform.parent = gameObject.transform
			renderers as (Renderer) = array[of Renderer](1)
			renderers[0] = go.renderer
			lods[i] = LOD((1.0F / (i + 1)), renderers)
			i++
		group.SetLODS(lods)
		group.RecalculateBounds()

	def OnGUI() as void:
		if GUILayout.Button('Enable / Disable'):
			group.enabled = (not group.enabled)
		if GUILayout.Button('Default'):
			group.ForceLOD(-1)
		if GUILayout.Button('Force 0'):
			group.ForceLOD(0)
		if GUILayout.Button('Force 1'):
			group.ForceLOD(1)
		if GUILayout.Button('Force 2'):
			group.ForceLOD(2)
		if GUILayout.Button('Force 3'):
			group.ForceLOD(3)
		if GUILayout.Button('Force 4'):
			group.ForceLOD(4)
		if GUILayout.Button('Force 5'):
			group.ForceLOD(5)
		if GUILayout.Button('Force 6'):
			group.ForceLOD(6)