feat: 캐릭터 스폰 오류 시 이후 코드 처리하지 않을 수 있도록 리턴타입 추가
This commit is contained in:
@@ -6,46 +6,40 @@ namespace TON
|
||||
{
|
||||
public class PlayerSpawner
|
||||
{
|
||||
public static void SpawnPlayerCharacter()
|
||||
public static bool SpawnPlayerCharacter()
|
||||
{
|
||||
List<PlayerData> playerDatas = PlayerDataManager.Singleton.playersData;
|
||||
// 저장된 인덱스 가져오기
|
||||
int selectedIndex = PlayerPrefs.GetInt("SelectedPlayerIndex", 0);
|
||||
|
||||
// 인덱스가 범위를 벗어나지 않는지 확인
|
||||
if (selectedIndex < 0 || selectedIndex >= playerDatas.Count)
|
||||
{
|
||||
Debug.LogError($"Invalid player index: {selectedIndex}");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
string prefabName = playerDatas[selectedIndex].type == "b" ? "TON.Player_B" : "TON.Player_W";
|
||||
// Resources에서 프리팹 로드
|
||||
GameObject characterPrefab = Resources.Load<GameObject>($"Player/{prefabName}");
|
||||
if (characterPrefab == null)
|
||||
{
|
||||
Debug.LogError($"Failed to load character prefab: {playerDatas[selectedIndex].type}");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// TON.Player 오브젝트 찾기
|
||||
GameObject playerObj = GameObject.Find("TON.Player");
|
||||
if (playerObj == null)
|
||||
{
|
||||
Debug.LogError("TON.Player not found in the scene!");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// 기존 플레이어 제거 (필요 시)
|
||||
foreach (Transform child in playerObj.transform)
|
||||
{
|
||||
GameObject.Destroy(child.gameObject);
|
||||
}
|
||||
|
||||
// 캐릭터 프리팹을 TON.Player 위치에 배치
|
||||
GameObject playerInstance = GameObject.Instantiate(characterPrefab, playerObj.transform.position, Quaternion.identity);
|
||||
playerInstance.transform.SetParent(playerObj.transform);
|
||||
|
||||
// 카메라가 새 플레이어를 따라가도록 설정
|
||||
CameraFollow cameraFollow = GameObject.FindObjectOfType<CameraFollow>();
|
||||
if (cameraFollow != null)
|
||||
@@ -55,7 +49,10 @@ namespace TON
|
||||
else
|
||||
{
|
||||
Debug.LogError("No CameraFollow script found in the scene!");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user