@TonyLi gave good suggestions, but here’s the technical aspect of what you want to do. Quoting from Unity - Manual: Level of Detail (LOD) for meshes :
LOD-based naming conventions in the asset import pipeline
In order to simplify setup of LODs, Unity has a naming convention for models that are being imported.
Simply create your meshes in your modelling tool with names ending with _LOD0, _LOD1, _LOD2, etc., and the LOD group with appropriate settings will be created for you.
Note that the convention assumes that the LOD 0 is the highest resolution model.
This should mean you can just set the naming convention and it will automatically pick up. I couldn’t make it work in practice, but it should work eventually. And, even if it doesn’t work, it’s just drag n’ drop the prefab into the lod group, quite easy.
Also, since your title is still confusing, I’ll answer it separately as well, just like @inkspot did, but with [code from the wiki][1]:
/*
Automatically set LOD Levels of models
(C)2010 by Tom Vogt
Use and modify as you wish, but retain author credits (aka BSD license)
== Usage ==
* Create an empty gameobject
* Drag all LOD levels into it, so they become children of the LOD object
* Attach this script to the empty gameobject
* Set the number of meshes in the script, and drag them into the slots, from highest (closest) to lowest (far away)
* Set the number of distances to
one less
than the number of meshes (beyond the highest distance will use the most far away mesh automatically)
* Set the distances at which the script shall switch to the next lowest LOD. So the first number means “at this distance or less, use the highest LOD”.
* Press Play and drag the camera around to check if your distances are fine.
*/
public var Distances : float[];
public var Models : GameObject[];
private var current = -2;
function Start() {
for (var i=0; i<Models.Length; i++) {
Models*.SetActiveRecursively(false);*
function Update() {
- var d = Vector3.Distance(camera.main.transform.position, transform.position);*
- var stage = -1;*
- for (var i=0; i<Distances.Length; i++) {*
_ if (d<Distances*) {_
_ stage=i;_
_ i=Distances.Length;_
_ }_
_ }_
_ if (stage==-1) stage=Distances.Length;_
_ if (current!=stage) {_
_ SetLOD(stage);_
_ }_
_}*_
function SetLOD(stage) {
* Models[stage].SetActiveRecursively(true);*
* if (current>=0) Models[current].SetActiveRecursively(false);*
* current = stage;*
}
[1]: http://wiki.unity3d.com/index.php/Simple_LOD_Manager