Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Lod : MonoBehaviour {
- public GameObject [] models;
- public int[] distance;
- private GameObject camera;
- private int numerModels;
- private float camDistance;
- void Start()
- {
- int i;
- for (i = 0; i < models.Length; i++)
- {
- models[i].SetActive(false);
- }
- camera = Camera.main.gameObject;
- }
- void Update()
- {
- camDistance = Vector3.Distance (camera.transform.position, transform.position);
- int lvl = -1;
- int i;
- for (i = 0; i < distance.Length; i++)
- {
- if (camDistance < distance [i])
- {
- lvl = i;
- i = distance.Length;
- }
- }
- if (lvl == -1)
- {
- lvl = distance.Length - 1;
- }
- if (numerModels != lvl)
- {
- SetLOD (lvl);
- }
- }
- void SetLOD(int lvl)
- {
- models[lvl].SetActive(true);
- models [numerModels].SetActive(false);
- numerModels = lvl;
- }
- }
Add Comment
Please, Sign In to add comment