타이머를 만들기 위해서 TimeSetup.cs를 만들었음.
여기서 DateTime.UtcNow를 이용해서 세계 표준시를 가져올 수 있다.
using System;
using UnityEngine;
public class TimeSetup : MonoBehaviour
{
public static TimeSpan timestamp;
public static int CheckTime()
{
timestamp = DateTime.UtcNow - new DateTime(2000,1,1,0,0,0); //2000년 1월 1일 0시 기준 현재의 time
int timesecond = (int)timestamp.TotalSeconds; //시간을 초로 환산
return timesecond;
}
}
위에서 정해둔 CheckTime() 메소드를 활용하고, 시간을 분/초로 적어두기 위해서는 아래와 같이 구현해야 한다.
int time = ButtonTime + currentTime - TimeSetup.CheckTime();
int minute = (int)time/60;
int second = (int)time%60;
timer.text = string.Format("{0:D2}:{1:D2}",minute,second);
'유니티' 카테고리의 다른 글
Particle System으로 만들어진 GameObject의 Rotation이 안되는 문제 (0) | 2023.03.28 |
---|---|
UI Panel, Prefab으로 지정하여 모든 Scene에서 로딩 (0) | 2023.03.27 |
[유니티] Prefab을 Script에서 불러오기(Resource 폴더 사용) (0) | 2023.03.16 |
[C#] 한 글자 씩 나타나게 하는 방법. Substring 이용. (0) | 2023.03.12 |
[유니티] DOTween이용해서 Panel 깜빡이기 (0) | 2023.03.09 |