This repository has been archived on 2023-09-13. You can view files and clone it, but cannot push or open issues or pull requests.
station_obscurum_unity/Assets/Scripts/Legacy/Player/CameraShift.cs

65 lines
1.7 KiB
C#
Raw Normal View History

using Cinemachine;
2023-06-01 17:03:48 +02:00
using UnityEngine;
2023-06-01 20:25:46 +02:00
namespace Player
{
2023-06-01 20:25:46 +02:00
public class CameraShift : MonoBehaviour
{
public static CameraShift active;
2023-06-01 17:03:48 +02:00
2023-06-01 20:25:46 +02:00
[SerializeField] private Camera childCam;
2023-06-01 17:03:48 +02:00
2023-06-01 20:25:46 +02:00
[SerializeField] private Transform offset;
2023-06-01 17:03:48 +02:00
2023-06-01 20:25:46 +02:00
[SerializeField] private float cameraSpeed = 5f;
2023-06-01 17:03:48 +02:00
2023-06-01 20:25:46 +02:00
[SerializeField] private CinemachineFreeLook freelook;
2023-06-01 17:03:48 +02:00
2023-06-01 20:25:46 +02:00
[SerializeField] private float initRadius = 3f;
2023-06-01 17:03:48 +02:00
2023-06-01 20:25:46 +02:00
[SerializeField] private float aimingRadius = 2f;
2023-06-01 20:25:46 +02:00
private bool isCenter = true;
private Vector3 targetOffset;
2023-06-01 20:25:46 +02:00
// Start is called before the first frame update
private void Start()
{
2023-06-01 17:03:48 +02:00
targetOffset = Vector3.zero;
}
2023-06-01 20:25:46 +02:00
// Update is called once per frame
private void Update()
{
2023-06-01 20:25:46 +02:00
active = this;
if (isCenter)
{
targetOffset = Vector3.zero;
freelook.m_Orbits[1].m_Radius =
Mathf.Lerp(freelook.m_Orbits[1].m_Radius, initRadius, Time.deltaTime * cameraSpeed);
}
else
{
targetOffset = offset.localPosition;
freelook.m_Orbits[1].m_Radius =
Mathf.Lerp(freelook.m_Orbits[1].m_Radius, aimingRadius, Time.deltaTime * cameraSpeed);
}
2023-06-01 17:03:48 +02:00
2023-06-01 20:25:46 +02:00
childCam.transform.localPosition =
Vector3.Lerp(childCam.transform.localPosition, targetOffset, Time.deltaTime * cameraSpeed);
}
//[SerializeField]
//private PlayerMovementController movementController;
2023-06-01 17:03:48 +02:00
2023-06-01 20:25:46 +02:00
public void ToggleCenter()
{
isCenter = !isCenter;
}
2023-06-01 17:03:48 +02:00
2023-06-01 20:25:46 +02:00
public void SetCenter(bool isCenter)
{
this.isCenter = isCenter;
}
}
2023-06-01 17:03:48 +02:00
}