Advertisement
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 int numberModel;
- private float dist;
- private bool mainCamActive;
- private bool gCamActive;
- public GameObject mainCamera;
- public GameObject cameraG;
- void Start()
- {
- int i;
- for (i = 0; i < models.Length; i++)
- {
- models[i].gameObject.SetActive(false);
- }
- }
- void Update()
- {
- mainCamActive = mainCamera.activeSelf;
- gCamActive = cameraG.activeSelf;
- if (mainCamActive == true)
- {
- dist = Vector3.Distance(mainCamera.transform.position, transform.position);
- }
- if (gCamActive == true)
- {
- dist = Vector3.Distance(cameraG.transform.position, transform.position);
- }
- int lvl = -1;
- int i;
- for (i = 0; i < distance.Length; i++)
- {
- if (dist < distance[i])
- {
- lvl = i;
- i = distance.Length;
- }
- }
- if (lvl == -1)
- {
- lvl = distance.Length - 1;
- }
- if (numberModel != lvl)
- {
- SetLOD(lvl);
- }
- }
- void SetLOD(int lvl)
- {
- models[lvl].gameObject.SetActive(true);
- models[numberModel].gameObject.SetActive(false);
- numberModel = lvl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement