씬 전환 기능 및 씬이 변경되어도 플레이어 정보를 유지하도록 게임 매니저 구현
This commit is contained in:
@@ -33,7 +33,7 @@ public class Player : MonoBehaviour
|
||||
[SerializeField] public int hp = 5;
|
||||
[SerializeField] public int maxHp = 5;
|
||||
|
||||
private bool isFacingRight = false;
|
||||
private bool isFacingRight = true;
|
||||
private int currentAnimationState = -1;
|
||||
|
||||
private Animator animator;
|
||||
@@ -69,9 +69,9 @@ public class Player : MonoBehaviour
|
||||
Debug.LogError($"{gameObject.name} 오브젝트에 SPUM_Prefabs 컴포넌트가 없습니다! 인스펙터를 확인하세요.");
|
||||
}
|
||||
|
||||
// 캐릭터 방향 기본 오른쪽 설정
|
||||
// 오리지널 리소스가 원래 왼쪽을 보고 있으므로, 시작 시 X 스케일을 반전시켜 즉시 오른쪽을 바라보도록 초기화합니다.
|
||||
Vector3 initialScale = transform.localScale;
|
||||
initialScale.x = Mathf.Abs(initialScale.x);
|
||||
initialScale.x = -Mathf.Abs(initialScale.x);
|
||||
transform.localScale = initialScale;
|
||||
|
||||
animator = GetComponentInChildren<Animator>();
|
||||
@@ -80,8 +80,34 @@ public class Player : MonoBehaviour
|
||||
|
||||
void Start()
|
||||
{
|
||||
// 시작 시 백엔드로부터 다음 세대 정보 조회
|
||||
StartCoroutine(GetNextGenerationFromServer());
|
||||
// 씬 로딩 후 GameManager에 이미 보존되어 넘어온 캐릭터 정보가 존재한다면 복구합니다.
|
||||
if (GameManager.Instance != null && !string.IsNullOrEmpty(GameManager.Instance.playerName))
|
||||
{
|
||||
characterName = GameManager.Instance.playerName;
|
||||
generation = GameManager.Instance.playerGeneration;
|
||||
hp = GameManager.Instance.playerHp;
|
||||
maxHp = GameManager.Instance.playerMaxHp;
|
||||
|
||||
// UI 텍스트 및 이미지 게이지 동기화
|
||||
if (nameText != null)
|
||||
{
|
||||
nameText.text = characterName;
|
||||
}
|
||||
|
||||
if (hpImage != null && maxHp > 0)
|
||||
{
|
||||
float fillRatio = Mathf.Clamp01((float)hp / maxHp);
|
||||
hpImage.fillAmount = fillRatio;
|
||||
hpImage.rectTransform.localScale = new Vector3(fillRatio, 1f, 1f);
|
||||
}
|
||||
|
||||
Debug.Log($"[Player] GameManager로부터 이전 캐릭터 정보를 무사히 인계받았습니다: {characterName} | HP: {hp}/{maxHp}");
|
||||
}
|
||||
else
|
||||
{
|
||||
// 데이터가 보존되지 않은 최초 기동 상태인 경우에만 백엔드 서버에서 신규 세대 번호를 조회하여 할당합니다.
|
||||
StartCoroutine(GetNextGenerationFromServer());
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
|
||||
Reference in New Issue
Block a user