37 lines
1.3 KiB
C#
37 lines
1.3 KiB
C#
|
using System;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.Serialization;
|
||
|
|
||
|
namespace DefaultNamespace
|
||
|
{
|
||
|
public class PlayerCameraController : MonoBehaviour
|
||
|
{
|
||
|
[SerializeField] private Transform logicalCamera;
|
||
|
[SerializeField] private Transform physicalCamera;
|
||
|
|
||
|
[SerializeField] private Transform pivot;
|
||
|
[SerializeField] private Transform minZoomTarget;
|
||
|
[SerializeField] private Transform maxZoomTarget;
|
||
|
|
||
|
private float _zoomAmount;
|
||
|
|
||
|
/// <summary>
|
||
|
/// Rotates the logical camera around the pivot by angle degrees.
|
||
|
/// </summary>
|
||
|
/// <param name="angle">The amount to rotate, in degrees</param>
|
||
|
public void RotateAround(float angle)
|
||
|
{
|
||
|
logicalCamera.RotateAround(pivot.position, Vector3.up, angle);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Lerps the physical camera between the min zoom target and the max zoom target by the current zoom + amount
|
||
|
/// </summary>
|
||
|
/// <param name="amount"></param>
|
||
|
public void Zoom(float amount)
|
||
|
{
|
||
|
_zoomAmount = Mathf.Clamp01(_zoomAmount + amount);
|
||
|
physicalCamera.localPosition = Vector3.Lerp(minZoomTarget.localPosition, maxZoomTarget.localPosition, _zoomAmount);
|
||
|
}
|
||
|
}
|
||
|
}
|