遊戲時間倒數
unknown
c_cpp
4 years ago
882 B
12
Indexable
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.SceneManagement;
public class timer : MonoBehaviour
{
public static bool IsGameOver = false;
public GameObject DontDestroy_Obj;
public TMP_Text timer_Text;
int time = 60;
// Start is called before the first frame update
void Start()
{
timer_Text = GetComponent<TMP_Text>();
}
// Update is called once per frame
void Update()
{
timer_Text.text = "Time:0" + time / 60 + ":" + time % 60;
if(time < 0.5)
{
timer_Text.text = "";
IsGameOver = true;
CancelInvoke();
}
}
void Countdown()
{
time--;
}
public void StartGame()
{
InvokeRepeating("Countdown", 0, 1);
}
}Editor is loading...