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);
}
}
}
'KDT > 유니티 기초' 카테고리의 다른 글
[SimpleRPG] 몬스터 피격시 피격 이펙트 입히기 (0) | 2023.08.10 |
---|---|
[SimpleRPG] 플레이어 이동과 공격 + 몬스터 공격시 피격 구현 (0) | 2023.08.09 |
[Apple Catch] Apple Catch 제작 (0) | 2023.08.07 |
[MoveHunt] 몬스터를 클릭하면 이동 후 공격, 바닥을 클릭하면 해당 위치로 이동 구현 (1) | 2023.08.06 |
[UnityChan] 캐릭터 화면 클릭 시 해당 위치로 이동하기 (0) | 2023.08.04 |