Hi, I have a script that generates meshes for rocks procedurally. This all works great, I can create endless random rocks that are all different. Now I am trying to create LOD groups for each of these rocks for optimisation purposes (obviously!). I know how to use the LOD Group component in the inspector, but I can’t seem to get a grip on how to add my meshes to it in code. My main problem is that I can’t figure out what the hell the LOD renderer wants me to add. It’s not a mesh, a meshFilter, a meshRender, the GameObject that contains the mesh, so what is it? Here’s a sample of my code:
GameObject sphere = new GameObject ("ICOSphere", typeof(MeshRenderer), typeof(MeshFilter), typeof(LODGroup));
sphere.transform.position = new Vector3 (2, 2, -2);
LODGroup lodGroup = sphere.GetComponent<LODGroup> ();
Renderer[] renderer = new Renderer[1];
renderer[0] = sphere.GetComponent<MeshRenderer>();
LOD[] lods = new LOD [3];
lods [0] = new LOD (0.5f, renderer);
lodGroup.SetLODS (lods);
the line:
renderer[0] = sphere.GetComponent<MeshRenderer>();
is where I’m currently struggling. although unity does infact allow me to use MeshRenderer here, it doesn’t seem to do anything. I would have expected this to either be a mesh or a gameObject (because you drag a gameObject into the LOD when you do it in the inspector).
I’m so confused. And my script contains the word LOD more times than I can make sense of it! :S
Cheers in advance for any pointers!
Pete