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;
- public GameObject camera;
- private int numerModels;
- private float camDistance;
- void Start()
- {
- int i;
- for (i = 0; i < models.Length; i++)
- {
- models[i].SetActive(false);
- }
- }
- void Update()
- {
- camDistance = Vector3.Distance(camera.transform.position, transform.position);
- int lvl = 0;
- int i;
- for (i = 0; i < distance.Length; i++)
- {
- if (camDistance < distance[i])
- {
- lvl = i;
- i = distance.Length;
- }
- }
- if (lvl == 0) // эта проверка лишняя?
- {
- lvl = distance.Length - 1;
- }
- if (numerModels != lvl)
- {
- SetLOD(lvl);
- }
- }
- void SetLOD(int lvl)
- {
- models[lvl].SetActive(true);
- models[numerModels].SetActive(false);
- numerModels = lvl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement