You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.3 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class Timer : MonoBehaviour {
  6. //Time stuff
  7. public float MaxTimer = 120.0f;
  8. float curTime = 0.0f;
  9. public Transform Pivot;
  10. public Transform Sun;
  11. float curRot = 0;
  12. public Color Dawn;
  13. public Color Noon;
  14. float DawnValue;
  15. float NoonValue;
  16. float colorDif;
  17. Image SunImage;
  18. public GameMode mode;
  19. void Start()
  20. {
  21. SunImage = Sun.gameObject.GetComponent<Image>();
  22. SunImage.color = Dawn;
  23. DawnValue = Dawn.b;
  24. NoonValue = Noon.b;
  25. colorDif = Mathf.Abs(NoonValue - DawnValue);
  26. }
  27. void Update () {
  28. curTime += 1.0f * Time.deltaTime;
  29. if (curTime >= MaxTimer)
  30. {
  31. mode.PreGameLose();
  32. }
  33. Color newColor;
  34. if (curTime > MaxTimer / 2)
  35. {
  36. newColor = new Color(SunImage.color.r, SunImage.color.g - colorDif * ((90 / MaxTimer) * Time.deltaTime), SunImage.color.b );
  37. }
  38. else
  39. {
  40. newColor = new Color(SunImage.color.r, SunImage.color.g + colorDif * ((90 / MaxTimer) * Time.deltaTime), SunImage.color.b);
  41. }
  42. SunImage.color = newColor;
  43. Sun.RotateAround(Pivot.transform.position, -1 * Sun.transform.forward, (180 / MaxTimer) * Time.deltaTime);
  44. }
  45. }