using UnityEngine; namespace Creatures.Player.Movement { public class CameraMove : MonoBehaviour { 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(); } // Start is called once before the first execution of Update after the MonoBehaviour is created void InitPosition() { Vector3 desiredCamPos = _player.position+_camOffset; _cameraTransform.position = desiredCamPos; _cameraTransform.LookAt(_player); } public void MoveCamera() { Vector3 desiredCamPos = _player.position+_camOffset; _cameraTransform.position = desiredCamPos; _cameraTransform.LookAt(_player); _cameraTransform.position = Vector3.Lerp(_cameraTransform.position, desiredCamPos, _followspeed*Time.deltaTime); } } }