twinStick/twinStickCrawler/Assets/Scripts/Creatures/Player/CameraMove.cs

35 lines
1.1 KiB
C#
Raw Normal View History

2024-12-17 21:46:05 +00:00
using UnityEngine;
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();
}
2024-12-17 21:46:05 +00:00
// Start is called once before the first execution of Update after the MonoBehaviour is created
void InitPosition()
2024-12-17 21:46:05 +00:00
{
Vector3 desiredCamPos = _player.position+_camOffset;
_cameraTransform.position = desiredCamPos;
_cameraTransform.LookAt(_player);
2024-12-17 21:46:05 +00:00
}
public void MoveCamera()
2024-12-17 21:46:05 +00:00
{
Vector3 desiredCamPos = _player.position+_camOffset;
_cameraTransform.position = desiredCamPos;
_cameraTransform.LookAt(_player);
2024-12-17 21:46:05 +00:00
_cameraTransform.position = Vector3.Lerp(_cameraTransform.position, desiredCamPos, _followspeed*Time.deltaTime);
2024-12-17 21:46:05 +00:00
}
}