2024-12-17 21:46:05 +00:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class CameraMove : MonoBehaviour
|
|
|
|
{
|
2024-12-19 19:21:36 +00:00
|
|
|
private Transform _cameraTransform;
|
|
|
|
private Transform _player;
|
|
|
|
private Vector3 _camOffset;
|
|
|
|
private float _followspeed;
|
|
|
|
public void initialize(Transform player, Vector3 camOffset, float followspeed, Transform cameraTransform)
|
|
|
|
{
|
|
|
|
_player = player;
|
|
|
|
_camOffset = camOffset;
|
|
|
|
_followspeed = followspeed;
|
|
|
|
_cameraTransform = cameraTransform;
|
|
|
|
|
|
|
|
InitPosition();
|
|
|
|
}
|
2024-12-17 21:46:05 +00:00
|
|
|
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
2024-12-19 19:21:36 +00:00
|
|
|
void InitPosition()
|
2024-12-17 21:46:05 +00:00
|
|
|
{
|
2024-12-19 19:21:36 +00:00
|
|
|
Vector3 desiredCamPos = _player.position+_camOffset;
|
|
|
|
_cameraTransform.position = desiredCamPos;
|
|
|
|
_cameraTransform.LookAt(_player);
|
2024-12-17 21:46:05 +00:00
|
|
|
}
|
2024-12-19 19:21:36 +00:00
|
|
|
|
|
|
|
public void MoveCamera()
|
2024-12-17 21:46:05 +00:00
|
|
|
{
|
2024-12-19 19:21:36 +00:00
|
|
|
Vector3 desiredCamPos = _player.position+_camOffset;
|
|
|
|
_cameraTransform.position = desiredCamPos;
|
|
|
|
_cameraTransform.LookAt(_player);
|
2024-12-17 21:46:05 +00:00
|
|
|
|
2024-12-19 19:21:36 +00:00
|
|
|
_cameraTransform.position = Vector3.Lerp(_cameraTransform.position, desiredCamPos, _followspeed*Time.deltaTime);
|
2024-12-17 21:46:05 +00:00
|
|
|
}
|
2024-12-19 19:21:36 +00:00
|
|
|
}
|