TKK_E32231768/Assets/6Script/quiz/coba random/TimerGame.cs

77 lines
1.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
public class TimerGame : MonoBehaviour
{
public Slider timerSlider;
public static bool isStop;
[Header("panel result if lose")]
public GameObject panelResult;
public Text textResult;
public Text textPoint;
//power up
public static bool isTimeStop;
public Button timeStopButton;
//timer text
public Text textTimer;
void Start()
{
isStop = false;
isTimeStop = false;
textTimer.text = TimeSpan.FromSeconds(timerSlider.value).ToString("mm':'ss");
}
void Update()
{
Timer();
}
void Timer()
{
if (isTimeStop == false)
{
if (isStop == false)
{
if (timerSlider.value > timerSlider.minValue) // 10 > 0
{
timerSlider.value -= Time.deltaTime;
string converterTime = TimeSpan.FromSeconds(timerSlider.value).ToString("mm':'ss");
textTimer.text = converterTime;
}
else
{
isStop = true;
Debug.Log(isStop + " isStop");
panelResult.SetActive(true);
textResult.text = "Waktumu Sudah Habis";
textPoint.text = "Point Akhir Kamu: " + Quest.totalPoint.ToString();
}
}
}
else
{
Debug.Log("time stop aktif");
}
}
public void ButtonPowerUpTimeStop()
{
isTimeStop = true;
timeStopButton.interactable = false;
}
}