Countdown.cs 1.08 KB
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class Countdown : MonoBehaviour
{
    float currentTime = 0f;
    float startingTime = 10f;
    public GameObject Target1;
    public GameObject Target2;

    [SerializeField] Text countdownText;
    [SerializeField] Text resultText;

    void Start()
    {
        currentTime = startingTime;
    }

    void Update()
    {
        currentTime -= 1 * Time.deltaTime;
        countdownText.text = currentTime.ToString("0");

        if(currentTime <= 0)
        {
            Target1.SetActive(true);
            Target2.SetActive(true);
            currentTime = 0;
            resultText.text = (1000 * ScoreCount.fakeScore).ToString() + "포인트\n 적립되었습니다!\n3초후 집으로\n돌아갑니다...";
            Invoke("exit_Game", 3);
            Target1.SetActive(false);
            Target2.SetActive(false);
        }
    }

    public void exit_Game()
    {
        SceneManager.LoadScene(2);
        ScoreCount.fakeScore = 0;
    }
}