Files

53 lines
1.6 KiB
C#

using UnityEngine;
public class GameManager : MonoBehaviour
{
// 외부에서 쉽게 접근할 수 있는 싱글톤 인스턴스
public static GameManager Instance { get; private set; }
[Header("보존할 플레이어 스탯 데이터")]
public string playerName = "";
public int playerGeneration = 1;
public int playerHp = 5;
public int playerMaxHp = 5;
private void Awake()
{
// 중복 생성 방지 및 싱글톤 유지
if (Instance != null && Instance != this)
{
Destroy(gameObject);
return;
}
Instance = this;
// 씬이 전환되어도 이 오브젝트가 파괴되지 않고 유지되도록 설정합니다.
DontDestroyOnLoad(gameObject);
}
// 플레이어 스탯을 동기적으로 복사하여 세이브하는 메서드
public void SavePlayerData(Player player)
{
if (player != null)
{
playerName = player.CharacterName;
playerGeneration = player.Generation;
playerHp = player.hp;
playerMaxHp = player.maxHp;
Debug.Log($"[GameManager] 캐릭터 정보 보존 세이브 완료: {playerName} ({playerGeneration}대) | HP: {playerHp}/{playerMaxHp}");
}
}
// 플레이어 보존 세션을 리셋하는 메서드 (사망 시 호출)
public void ClearPlayerData()
{
playerName = "";
playerGeneration = 1;
playerHp = 5;
playerMaxHp = 5;
Debug.Log("[GameManager] 보존된 이전 플레이어 스탯 데이터를 비웠습니다. (신규 세대 생성 준비 완료)");
}
}