leomovskii

TimeDemo.cs

Nov 29th, 2021 (edited)
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class TimeDemo : MonoBehaviour
  6. {
  7.     string[] monthsList = { "січ", "лют", "бер", "кві", "тра", "чер", "лип", "сер", "вер", "жов", "лис", "гру" };
  8.  
  9.     public int years; // рік
  10.     public int months = 1; // місяць
  11.     public int days = 1; // день
  12.     public int hours; // час
  13.     public int minutes; // хвилина
  14.     public int seconds; // секунда
  15.     float counter; // лічильник
  16.  
  17.     void FixedUpdate()
  18.     {
  19.         counter += Time.fixedDeltaTime;
  20.        
  21.         if (counter >= 1f) {
  22.             seconds++;
  23.             counter = 0;
  24.             if (seconds > 59) {
  25.                 seconds = 0;
  26.                 minutes++;
  27.                 if (minutes > 59) {
  28.                     minutes = 0;
  29.                     hours++;
  30.                     if (hours > 23) {
  31.                         hours = 0;
  32.                         days++;
  33.                         if (days > 30) {
  34.                             days = 1;
  35.                             months++;
  36.                             if (months > 12) {
  37.                                 months = 1;
  38.                                 years++;
  39.                             }
  40.                         }
  41.                     }
  42.                 }
  43.             }
  44.             string sec = (seconds < 10 ? "0" : "") + seconds.ToString();
  45.             string min = (minutes < 10 ? "0" : "") + minutes.ToString();
  46.             string hr = (hours < 10 ? "0" : "") + hours.ToString();
  47.            
  48.             string dd = (days < 10 ? "0" : "") + days.ToString();
  49.             string mm = monthsList[months - 1];
  50.             string yy = years.ToString();
  51.            
  52.             Debug.Log(hr + ":" + min + ":" + sec + " " + dd + " " + mm + " " + yy);
  53.         }
  54.     }
  55. }
Add Comment
Please, Sign In to add comment