feat: Stage 1 캐릭터 follow 카메라 추가 작업
This commit is contained in:
31
Gameton-06/Assets/Gameton/Scripts/Camera/CameraFollow.cs
Normal file
31
Gameton-06/Assets/Gameton/Scripts/Camera/CameraFollow.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Cinemachine;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
|
||||
public class CameraFollow : MonoBehaviour
|
||||
{
|
||||
private CinemachineVirtualCamera vcam;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
vcam = GetComponent<CinemachineVirtualCamera>();
|
||||
if (vcam == null)
|
||||
{
|
||||
Debug.LogError("Cinemachine Virtual Camera component is missing!");
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFollowTarget(Transform target)
|
||||
{
|
||||
if (vcam != null)
|
||||
{
|
||||
vcam.Follow = target;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 58f4ec2a370c10c44a9a548e6cfd2d74
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -4,9 +4,8 @@ using UnityEngine;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
public static class PlayerSpawner
|
||||
public class PlayerSpawner
|
||||
{
|
||||
|
||||
public static void SpawnPlayerCharacter()
|
||||
{
|
||||
List<PlayerData> playerDatas = PlayerDataManager.Singleton.playersData;
|
||||
@@ -46,6 +45,17 @@ namespace TON
|
||||
// 캐릭터 프리팹을 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)
|
||||
{
|
||||
cameraFollow.SetFollowTarget(playerInstance.transform);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("No CameraFollow script found in the scene!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user