KorolevDmitry123

Untitled

Jul 7th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Lod : MonoBehaviour {
  5. public GameObject [] models;
  6. public int[] distance;
  7. private GameObject camera;
  8. private int numerModels;
  9. private float camDistance;
  10. void Start()
  11. {
  12. int i;
  13. for (i = 0; i < models.Length; i++)
  14. {
  15. models[i].SetActive(false);
  16. }
  17. camera = Camera.main.gameObject;
  18. }
  19. void Update()
  20. {
  21. camDistance = Vector3.Distance (camera.transform.position, transform.position);
  22. int lvl = -1;
  23. int i;
  24. for (i = 0; i < distance.Length; i++)
  25. {
  26. if (camDistance < distance [i])
  27. {
  28. lvl = i;
  29. i = distance.Length;
  30. }
  31. }
  32. if (lvl == -1)
  33. {
  34. lvl = distance.Length - 1;
  35. }
  36. if (numerModels != lvl)
  37. {
  38. SetLOD (lvl);
  39. }
  40. }
  41. void SetLOD(int lvl)
  42. {
  43. models[lvl].SetActive(true);
  44. models [numerModels].SetActive(false);
  45. numerModels = lvl;
  46. }
  47. }
Add Comment
Please, Sign In to add comment