씬 전환 기능 및 씬이 변경되어도 플레이어 정보를 유지하도록 게임 매니저 구현

This commit is contained in:
김민구
2026-07-08 04:24:12 +09:00
parent 8f742e50d9
commit 6939015d9e
8 changed files with 456 additions and 25 deletions
@@ -0,0 +1,42 @@
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}");
}
}
}