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.

55 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. void Start()
  19. {
  20. SunImage = Sun.gameObject.GetComponent<Image>();
  21. SunImage.color = Dawn;
  22. DawnValue = Dawn.b;
  23. NoonValue = Noon.b;
  24. colorDif = Mathf.Abs(NoonValue - DawnValue);
  25. }
  26. void Update () {
  27. curTime += 1.0f * Time.deltaTime;
  28. if (curTime >= MaxTimer)
  29. {
  30. //Game Lose code here
  31. }
  32. Color newColor;
  33. if (curTime > MaxTimer / 2)
  34. {
  35. newColor = new Color(SunImage.color.r, SunImage.color.g - colorDif * ((90 / MaxTimer) * Time.deltaTime), SunImage.color.b );
  36. }
  37. else
  38. {
  39. newColor = new Color(SunImage.color.r, SunImage.color.g + colorDif * ((90 / MaxTimer) * Time.deltaTime), SunImage.color.b);
  40. }
  41. SunImage.color = newColor;
  42. Sun.RotateAround(Pivot.transform.position, -1 * Sun.transform.forward, (180 / MaxTimer) * Time.deltaTime);
  43. }
  44. }