| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class TimerScript : MonoBehaviour
- {
- Image circleImage;
- Color circleColor;
- public Text timerText;
- float time;
- float timeAmount;
- Color finalColor = new Color32(130,0,16,220);
- Color startlColor = new Color32(16, 0, 255, 200);
- // Start is called before the first frame update
- void Start()
- {
- circleImage = this.GetComponent<Image>();
- time = PlayerPrefs.GetInt("QuestionTimer");
- timeAmount = time;
- circleColor = circleImage.color;
- timerText.text = time.ToString("F0");
- }
- // Update is called once per frame
- void Update()
- {
- circleColor = circleImage.color;
- if (time > 0) {
- time -= Time.deltaTime;
- circleColor = Color.Lerp(startlColor, finalColor, 1-(time/timeAmount));
- circleImage.color = circleColor;
- timerText.text = time.ToString("F0");
- }
- }
- }
|