TimerScript.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class TimerScript : MonoBehaviour
  6. {
  7. Image circleImage;
  8. Color circleColor;
  9. public Text timerText;
  10. float time;
  11. float timeAmount;
  12. Color finalColor = new Color32(130,0,16,220);
  13. Color startlColor = new Color32(16, 0, 255, 200);
  14. // Start is called before the first frame update
  15. void Start()
  16. {
  17. circleImage = this.GetComponent<Image>();
  18. time = PlayerPrefs.GetInt("QuestionTimer");
  19. timeAmount = time;
  20. circleColor = circleImage.color;
  21. timerText.text = time.ToString("F0");
  22. }
  23. // Update is called once per frame
  24. void Update()
  25. {
  26. circleColor = circleImage.color;
  27. if (time > 0) {
  28. time -= Time.deltaTime;
  29. circleColor = Color.Lerp(startlColor, finalColor, 1-(time/timeAmount));
  30. circleImage.color = circleColor;
  31. timerText.text = time.ToString("F0");
  32. }
  33. }
  34. }