| | | 1 | | using System.Collections; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using TMPro; |
| | | 4 | | using UnityEngine; |
| | | 5 | | |
| | | 6 | | public class TimerHandler : MonoBehaviour |
| | | 7 | | { |
| | 29 | 8 | | private float currentTime = 0; |
| | 29 | 9 | | private int currentSeconds = 0; |
| | 29 | 10 | | private int heures = 0; |
| | 29 | 11 | | private int minutes = 0; |
| | 29 | 12 | | private int seconds = 0; |
| | 29 | 13 | | private bool isRunning = true; |
| | | 14 | | [SerializeField] private TextMeshProUGUI display; |
| | | 15 | | [SerializeField] private SavedTime timeSaved; |
| | | 16 | | |
| | | 17 | | // Update is called once per frame |
| | | 18 | | private void Update() |
| | 8888 | 19 | | { |
| | 8888 | 20 | | if (isRunning) |
| | 8888 | 21 | | { |
| | 8888 | 22 | | currentTime += Time.deltaTime; |
| | 8888 | 23 | | currentSeconds = Mathf.FloorToInt(currentTime % 60); |
| | 8888 | 24 | | if (currentSeconds != seconds) //Si une seconde s'est �coul� depuis la derni�re mise � jour du texte, mettr |
| | 1235 | 25 | | { |
| | 1235 | 26 | | seconds = currentSeconds; |
| | 1235 | 27 | | heures = Mathf.FloorToInt(currentSeconds / 3600); |
| | 1235 | 28 | | minutes = Mathf.FloorToInt((currentTime % 3600) / 60); |
| | 1235 | 29 | | display.text = $"{heures:d2}:{minutes:d2}:{seconds:d2}"; |
| | 1235 | 30 | | } |
| | 8888 | 31 | | } |
| | 8888 | 32 | | } |
| | | 33 | | |
| | | 34 | | public void PauseTimer() |
| | 0 | 35 | | { |
| | 0 | 36 | | isRunning = false; |
| | 0 | 37 | | } |
| | | 38 | | |
| | | 39 | | public void ResumeTimer() |
| | 0 | 40 | | { |
| | 0 | 41 | | isRunning = true; |
| | 0 | 42 | | } |
| | | 43 | | |
| | | 44 | | public void ResetTimer() |
| | 0 | 45 | | { |
| | 0 | 46 | | currentTime = 0; |
| | 0 | 47 | | isRunning = true; |
| | 0 | 48 | | } |
| | | 49 | | |
| | | 50 | | public void SaveTime() |
| | 0 | 51 | | { |
| | 0 | 52 | | timeSaved.time = currentTime; |
| | 0 | 53 | | } |
| | | 54 | | |
| | | 55 | | public string GetTime() |
| | 0 | 56 | | { |
| | 0 | 57 | | return display.text; |
| | 0 | 58 | | } |
| | | 59 | | } |