BGJ-2022.1/Assets/Scripts/Camera/CameraPlayerFinder.cs

41 lines
1.4 KiB
C#

using Cinemachine;
using Level;
using UnityEngine;
using UnityEngine.U2D;
namespace Camera
{
public class CameraPlayerFinder : MonoBehaviour
{
private const float FollowOrthoSize = 7.5f;
private const float FixedOrthoSize = 15f;
private CinemachineVirtualCamera _cinemachineVirtualCamera;
private PixelPerfectCamera pixelPerfectCamera = null;
private void Awake()
{
_cinemachineVirtualCamera = GetComponent<CinemachineVirtualCamera>();
pixelPerfectCamera = GameObject.FindObjectOfType<PixelPerfectCamera>();
}
private void Update()
{
if (LevelManager.Instance.CurrentLevel?.FixedCameraPoint == null)
{
if (_cinemachineVirtualCamera.Follow == null)
{
_cinemachineVirtualCamera.Follow = LevelManager.Instance.Player.transform;
_cinemachineVirtualCamera.m_Lens.OrthographicSize = FollowOrthoSize;
pixelPerfectCamera.enabled = false;
}
}
else if (_cinemachineVirtualCamera.Follow != LevelManager.Instance.CurrentLevel.FixedCameraPoint)
{
_cinemachineVirtualCamera.Follow = LevelManager.Instance.CurrentLevel.FixedCameraPoint;
// _cinemachineVirtualCamera.m_Lens.OrthographicSize = FixedOrthoSize;
pixelPerfectCamera.enabled = true;
}
}
}
}