앞의 Energy Slider에서 오프라인에서 접속하였을 경우 추가, ticket에 맞게 변경
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System;
public class UIEnergy : MonoBehaviour
{
public TMP_Text txtTime;
public TMP_Text txtEnergy;
public Button btnUseEnergy;
private int energy = 5;
private int maxEnergy = 5;
private int energyTime = 3;
private bool chargeOn = false;
private DateTime chargeStartTime;
void Start()
{
this.btnUseEnergy.onClick.AddListener(() =>
{
Debug.Log("btnUseEnergy clicked");
if(this.energy!=0) this.energy--;
if (this.chargeOn == false)
{
this.chargeOn = true;
this.chargeStartTime = DateTime.Now;
}
});
}
private void Update()
{
if (this.chargeOn == true)
{
TimeSpan timeCal = DateTime.Now - this.chargeStartTime;
int timeSeconds = timeCal.Seconds;
int min = (this.energyTime - timeSeconds) / 60;
int sec = (this.energyTime - timeSeconds) % 60;
this.txtTime.text = String.Format("{0:00}:{1:00}", min, sec);
if (timeSeconds >= energyTime)
{
if(timeSeconds-energyTime > energyTime)
{
int n = 0;
while (timeSeconds < energyTime)
{
n++;
timeSeconds -= energyTime;
}
this.energy += n;
}
else
{
this.energy++;
if (this.energy == this.maxEnergy)
{
this.txtTime.text = "00:00";
Debug.Log("charge off");
this.chargeOn = false;
}
this.chargeStartTime = DateTime.Now;
}
}
}
this.txtEnergy.text = String.Format("{0}/{1}", this.energy, this.maxEnergy);
}
}
https://narmhye.tistory.com/96
'Project > <team Not Same> 꿈의 왕국 : 영원한 보금자리' 카테고리의 다른 글
[PJ] UIStage 데이터테이블 연동, 추상팩토리와 빌더 패턴 (0) | 2023.05.01 |
---|---|
[R&D] UI small Stage Map UIPlayer Move (0) | 2023.05.01 |
[GPGS] 프로젝트에 로그인 연동하기2 (0) | 2023.04.23 |
[GPGS] 프로젝트에 로그인 연동하기1 (0) | 2023.04.23 |
[R&D] Energy bar Slider (0) | 2023.04.11 |