UPF/Assets/Game/Scripts/Minigame/CameraFollower.cs

36 lines
997 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollower : MonoBehaviour
{
public bool autoOffset = true;
public Vector3 offset;
public Transform target;
public float minFOV = 11;
public float FOVmultiplier = 5;
public float smoothness = 0.1f;
void Start()
{
if(target==null){return;}
if(autoOffset){SetAutoOffset();}
}
// Update is called once per frame
void FixedUpdate()
{
if(target==null){return;}
transform.position = Vector3.Lerp(transform.position, target.position + offset, smoothness * Time.deltaTime);
GetComponent<Camera>().orthographicSize = minFOV + ((target.localScale.x - 1) * FOVmultiplier);
}
public void SetTarget(Transform Target){
target = Target;
if(autoOffset){SetAutoOffset();}
}
void SetAutoOffset(){
offset = transform.position - target.position;
}
}