| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- using System;
- 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;
- public bool mainTimer;
- bool timerRunning = false;
- Color finalColor = new Color32(130,0,16,220);
- Color startlColor = new Color32(16, 0, 255, 200);
- GameManagerScript gms;
- [SerializeField] GameObject dialogTimer;
- TimerScript dialogTimerScript;
- // Start is called before the first frame update
- void Start()
- {
- dialogTimerScript = dialogTimer.GetComponent<TimerScript>();
- gms = GameObject.Find("GameManager").GetComponent<GameManagerScript>();
- circleImage = this.GetComponent<Image>();
-
- circleColor = circleImage.color;
- timerText.text = time.ToString("F0");
- }
- public void StopTimer() {
- timerRunning = false;
- dialogTimerScript.timerRunning = false;
- }
- public void ResetTimer() {
- time = gms.QuestionTimer;
- // time = Database.Instance.GetQuestionTimer(gms.GameId, gms.GameMode);
- timeAmount = time;
- circleColor = Color.Lerp(startlColor, finalColor, 1 - (time / timeAmount));
- dialogTimerScript.time = time;
- dialogTimerScript.timeAmount = timeAmount;
- dialogTimerScript.circleImage.color = circleColor;
- dialogTimerScript.timerText.text = time.ToString("F0");
- circleImage.color = circleColor;
- timerText.text = time.ToString("F0");
- }
- // Update is called once per frame
- void Update()
- {
- if (timerRunning) {
- 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");
- } else {
- timerRunning = false;
- // send message to fail question
- if (mainTimer) {
- EventManager.TriggerEvent("TimerEvent");
- }
- }
- }
- }
- internal void StartTimer() {
- timerRunning = true;
- dialogTimerScript.timerRunning = true;
- }
- }
|