
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
코드를 따라서 쳤는데요. 카메라가 고정이 되어서 안 움직입니다.
오류도 안 떠서 어떻게 해결해야 할 지 모르겠어요.
작성한 코드 및 에러 메세지
using UnityEngine;
using System.Collections;
using TMPro;
public class GameManager : MonoBehaviour
{
public static GameManager Instance;
public bool IsGameEnd;
[HideInInspector] public Transform PlayerTransform;
public Vector3 currentSavePoint;
[SerializeField] private TextMeshProUGUI timeTxt;
[SerializeField] private TextMeshProUGUI bestScoreTxt;
[SerializeField] private GameObject[] CharacterPrefabs;
private PlayerAnimatorController animatorController;
private float elaspedTime = 0f;
private float bestScore = 0f;
void Start()
{
Instance = this;
animatorController = Instantiate(CharacterPrefabs[PlayerPrefs.GetInt("SelectedCharacter", 0)], currentSavePoint, Quaternion.identity).GetComponent<PlayerAnimatorController>();
IsGameEnd = false;
timeTxt.text = $"{elaspedTime:0.00}";
bestScore = PlayerPrefs.GetFloat("BestScore", 99.99f);
bestScoreTxt.text = $"BEST : {bestScore:0.00}";
}
void Update()
{
if (IsGameEnd) return;
elaspedTime += Time.deltaTime;
timeTxt.text = $"{elaspedTime:0.00}";
}
public void EndGame(bool isWin)
{
StartCoroutine(StopGameGradually());
IsGameEnd = true;
if (isWin)
{
if (elaspedTime < bestScore) PlayerPrefs.SetFloat("BestScore", elaspedTime);
}
}
IEnumerator StopGameGradually()
{
float time = 0f;
while (time < .5f)
{
time += Time.deltaTime;
Time.timeScale = Mathf.Lerp(1f, 0f, time * 2f);
yield return null;
}
}
}
using UnityEngine;
public class PlayerCameraController : MonoBehaviour
{
[SerializeField] private Vector3 cameraOffset;
private Camera cam;
void Start()
{
cam = Camera.main;
//Debug.Log("여기");
}
void LateUpdate()
{
//Debug.Log("여기2");
if (GameManager.Instance.PlayerTransform == null) return;
HandleCamera();
}
private void HandleCamera()
{
//Debug.Log("여기4");
Quaternion playerRotation = GameManager.Instance.PlayerTransform.rotation;
Vector3 rotatedOffset = playerRotation * cameraOffset;
cam.transform.position = GameManager.Instance.PlayerTransform.position + rotatedOffset;
cam.transform.LookAt(GameManager.Instance.PlayerTransform);
}
}
