58 lines
1.5 KiB
C#
58 lines
1.5 KiB
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using Cinemachine;
|
||
|
|
||
|
public class CameraShift : MonoBehaviour
|
||
|
{
|
||
|
[SerializeField]
|
||
|
private Camera childCam;
|
||
|
[SerializeField]
|
||
|
private Transform offset;
|
||
|
private bool isCenter = true;
|
||
|
private Vector3 targetOffset;
|
||
|
[SerializeField]
|
||
|
private float cameraSpeed = 5f;
|
||
|
[SerializeField]
|
||
|
private CinemachineFreeLook freelook;
|
||
|
private float initRadius = 3f;
|
||
|
private float aimingRadius = 2f;
|
||
|
//[SerializeField]
|
||
|
//private PlayerMovementController movementController;
|
||
|
|
||
|
|
||
|
public void ToggleCenter()
|
||
|
{
|
||
|
isCenter = !isCenter;
|
||
|
}
|
||
|
public void SetCenter(bool isCenter)
|
||
|
{
|
||
|
this.isCenter = isCenter;
|
||
|
}
|
||
|
|
||
|
// Start is called before the first frame update
|
||
|
void Start()
|
||
|
{
|
||
|
targetOffset = Vector3.zero;
|
||
|
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
// Update is called once per frame
|
||
|
void Update()
|
||
|
{
|
||
|
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);
|
||
|
}
|
||
|
}
|