using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class GameDirector : MonoBehaviour
{
    [SerializeField]
    private Text txtTime;
    [SerializeField]
    private Text txtScore;
    [SerializeField]
    private Text txtHighScore;

    private float time = 10.0f;
    private int score = 0;


    void Start()
    {
        this.UpdateScoreUI();

        // 노란색 바구니가 선택된 경우 시간 +10초
        if (GameManager.instance.selectedBasketType == BasketType.Yellow)
        {
            this.time += 10.0f;
        }
    }

    public void UpdateScoreUI()
    {
        this.txtScore.text = string.Format("Score: {0}", score);
        this.txtHighScore.text = string.Format("High Score: {0}", GameManager.instance.HighScore);
    }

    public void IncreaseScore(int score)
    {
        this.score += score;
    }

    public void DecreaseScore(int score)
    {
        this.score -= score;
    }

    // 시간을 늘리는 메서드
    public void IncreaseTime(float addedTime)
    {
        this.time += addedTime;
    }

    public float GetCurrentTime()
    {
        return this.time;
    }

    void Update()
    {
        this.time -= Time.deltaTime;    // 매프레임마다 감소된 시간을 표시
        this.txtTime.text = this.time.ToString("F1");   // 소수점 1자리까지 표시
        GameManager.instance.Score = this.score;

        if (this.score >= GameManager.instance.HighScore)
        {
            GameManager.instance.HighScore = this.score;
        }

        // Score or HighScore 변경 사항이 UI에 즉시 반영됩니다.
        this.UpdateScoreUI();

        if (this.time <= 0)
        {
            SceneManager.LoadScene("GameOver");
        }
    }
}
using UnityEngine;

public class GameManager : MonoBehaviour
{
    public static GameManager instance = null; 
    public GameObject selectedBasket; // 선택된 바구니
    public Material selectedMaterial; // 선택된 바구니의 Material
    public BasketType selectedBasketType; // 선택된 바구니의 유형
    public int Score;
    public int HighScore;

    void Awake()
    {
        if (instance == null)
        {
            instance = this;
            selectedBasket = null; // 선택된 바구니 초기화
            selectedMaterial = null; // 선택된 바구니의 Material 초기화
            selectedBasketType = BasketType.Red; // 초기 바구니 유형 설정
            DontDestroyOnLoad(gameObject); // 씬 변경 시 파괴 방지
            Score = 0;
            HighScore = 0;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }
    }

}

+ Recent posts