Advertisement
Guest User

Untitled

a guest
Dec 29th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityStandardAssets.ImageEffects;
  6. using TMPro;
  7.  
  8. public class DayNightCycle : MonoBehaviour {
  9.  
  10. public Light sun;
  11. public float secondsInFullDay = 120f;
  12.  
  13. //[Range(0, 1)]
  14. public float currentTimeOfDay = 0.16f;
  15.  
  16. [HideInInspector]
  17. public float timeMultiplier = 1f;
  18.  
  19. public TextMeshProUGUI dayText;
  20. public int day;
  21.  
  22. float sunInitialIntensity = 0.8f;
  23.  
  24. public SunShafts sunShaft;
  25. float sunShaftIntensity;
  26.  
  27.  
  28. void Start()
  29. {
  30. day = 1;
  31. dayText.text = "DAY: " + day;
  32.  
  33. sunInitialIntensity = sun.intensity;
  34.  
  35. sunShaftIntensity = sunShaft.sunShaftIntensity;
  36. }
  37.  
  38. void Update()
  39. {
  40. UpdateSun();
  41.  
  42. currentTimeOfDay += (Time.deltaTime / secondsInFullDay) * timeMultiplier;
  43.  
  44. if (currentTimeOfDay >= 1)
  45. {
  46. currentTimeOfDay = 0;
  47. }
  48.  
  49. if(currentTimeOfDay >= 0.40f && currentTimeOfDay <= 0.401f)
  50. {
  51. day += 1;
  52. dayText.text = "DAY: " + day;
  53. }
  54. }
  55.  
  56. void UpdateSun()
  57. {
  58. sun.transform.localRotation = Quaternion.Euler((currentTimeOfDay * 360f) - 35, 170, 0);
  59.  
  60. float sunIntensityMultiplier = 1;
  61.  
  62. float shaftIntensityMultiplier = 1;
  63.  
  64. if (currentTimeOfDay <= 0.23f || currentTimeOfDay >= 0.75f)
  65. {
  66. sunIntensityMultiplier = 0.2f;
  67.  
  68. shaftIntensityMultiplier = 0f;
  69. }
  70.  
  71. else if (currentTimeOfDay <= 0.25f)
  72. {
  73. sunIntensityMultiplier = Mathf.Clamp01((currentTimeOfDay - 0.25f) * (1 / 0.02f));
  74.  
  75. shaftIntensityMultiplier = Mathf.Clamp01((currentTimeOfDay - 0.25f) * (1 / 0.02f));
  76. }
  77.  
  78. else if (currentTimeOfDay >= 0.73f)
  79. {
  80. sunIntensityMultiplier = Mathf.Clamp01(1 - ((currentTimeOfDay - 0.73f) * (1 / 0.02f)));
  81.  
  82. shaftIntensityMultiplier = Mathf.Clamp01(1 - ((currentTimeOfDay - 0.73f) * (1 / 0.02f)));
  83. }
  84.  
  85. sun.intensity = sunInitialIntensity * sunIntensityMultiplier;
  86.  
  87. sunShaft.sunShaftIntensity = sunShaftIntensity * shaftIntensityMultiplier;
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement