Advertisement
KorolevDmitry123

Untitled

Jul 7th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 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 int numberModel;
  8. private float dist;
  9. private bool mainCamActive;
  10. private bool gCamActive;
  11. public GameObject mainCamera;
  12. public GameObject cameraG;
  13. void Start()
  14. {
  15. int i;
  16. for (i = 0; i < models.Length; i++)
  17. {
  18. models[i].gameObject.SetActive(false);
  19. }
  20. }
  21. void Update()
  22. {
  23. mainCamActive = mainCamera.activeSelf;
  24. gCamActive = cameraG.activeSelf;
  25. if (mainCamActive == true)
  26. {
  27. dist = Vector3.Distance (mainCamera.transform.position, transform.position);
  28. }
  29. if (gCamActive == true)
  30. {
  31. dist = Vector3.Distance (cameraG.transform.position, transform.position);
  32. }
  33. int lvl = -1;
  34. int i;
  35. for (i = 0; i < distance.Length; i++)
  36. {
  37. if (dist < distance[i])
  38. {
  39. lvl = i;
  40. i = distance.Length;
  41. }
  42. }
  43. if (lvl == -1)
  44. {
  45. lvl = distance.Length - 1;
  46. }
  47. if (numberModel != lvl)
  48. {
  49. SetLOD(lvl);
  50. }
  51. }
  52. void SetLOD(int lvl)
  53. {
  54. models[lvl].gameObject.SetActive(true);
  55. models[numberModel].gameObject.SetActive(false);
  56. numberModel = lvl;
  57. }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement