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

41 lines
1.4 KiB
C#
Raw Normal View History

2022-02-25 23:38:09 +03:00
using Cinemachine;
2022-02-27 00:43:46 +03:00
using Level;
2022-02-25 23:38:09 +03:00
using UnityEngine;
2022-02-27 00:43:46 +03:00
using UnityEngine.U2D;
2022-02-25 23:38:09 +03:00
namespace Camera
{
public class CameraPlayerFinder : MonoBehaviour
{
2022-02-27 00:43:46 +03:00
private const float FollowOrthoSize = 7.5f;
private const float FixedOrthoSize = 15f;
2022-02-25 23:38:09 +03:00
private CinemachineVirtualCamera _cinemachineVirtualCamera;
2022-02-27 00:43:46 +03:00
private PixelPerfectCamera pixelPerfectCamera = null;
2022-02-25 23:38:09 +03:00
private void Awake()
{
_cinemachineVirtualCamera = GetComponent<CinemachineVirtualCamera>();
2022-02-27 00:43:46 +03:00
pixelPerfectCamera = GameObject.FindObjectOfType<PixelPerfectCamera>();
2022-02-25 23:38:09 +03:00
}
private void Update()
{
2022-02-27 00:43:46 +03:00
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;
}
2022-02-25 23:38:09 +03:00
}
}
2022-02-27 00:43:46 +03:00
}