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
MarcoHampel f8590432ba Assemblies Made and Refactored Code Folders
Created assemblies for the new design code. Relocated legacy scripts into a legacy folder and made a "new_design" folder for new design.
2023-09-11 19:39:27 -04:00

65 lines
1.7 KiB
C#

using Cinemachine;
using UnityEngine;
namespace Player
{
public class CameraShift : MonoBehaviour
{
public static CameraShift active;
[SerializeField] private Camera childCam;
[SerializeField] private Transform offset;
[SerializeField] private float cameraSpeed = 5f;
[SerializeField] private CinemachineFreeLook freelook;
[SerializeField] private float initRadius = 3f;
[SerializeField] private float aimingRadius = 2f;
private bool isCenter = true;
private Vector3 targetOffset;
// Start is called before the first frame update
private void Start()
{
targetOffset = Vector3.zero;
}
// Update is called once per frame
private void Update()
{
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);
}
childCam.transform.localPosition =
Vector3.Lerp(childCam.transform.localPosition, targetOffset, Time.deltaTime * cameraSpeed);
}
//[SerializeField]
//private PlayerMovementController movementController;
public void ToggleCenter()
{
isCenter = !isCenter;
}
public void SetCenter(bool isCenter)
{
this.isCenter = isCenter;
}
}
}