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.

58 lines
1.4 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  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 float Dawn = 125; //FF7D00 125
  13. public float Noon = 248; //FFF800 248
  14. public float sunR;
  15. public float sunB;
  16. float sunG;
  17. float colorDif;
  18. public Image SunImage;
  19. public GameMode mode;
  20. public GameObject lightObj;
  21. void Start()
  22. {
  23. sunG = Dawn;
  24. colorDif = Mathf.Abs(Noon - Dawn);
  25. }
  26. void Update () {
  27. curTime += 1.0f * Time.deltaTime;
  28. if (curTime >= MaxTimer)
  29. {
  30. mode.PreGameLose();
  31. }
  32. float offset = colorDif * (2 / MaxTimer) * Time.deltaTime;
  33. if (curTime > MaxTimer / 2)
  34. {
  35. sunG -= offset;
  36. }
  37. else
  38. {
  39. sunG += offset;
  40. }
  41. Color32 col = new Color32((byte)sunR, (byte)sunG, (byte)sunB, (byte)255);
  42. Debug.Log(col);
  43. SunImage.color = col;
  44. Sun.RotateAround(Pivot.transform.position, -1 * Sun.transform.forward, (180 / MaxTimer) * Time.deltaTime);
  45. lightObj.transform.RotateAround(lightObj.transform.position, -1 * Sun.transform.forward, (180 / MaxTimer) * Time.deltaTime);
  46. }
  47. }