unity 2d camera followingh player code example
Example: camera follow player unity 2d
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
public Transform target;
public Vector3 offset;
[Range(1, 10)]
public float smoothing;
private void FixedUpdate()
{
Follow();
}
void Follow()
{
Vector3 targetPosition = target.position + offset;
Vector3 smoothPosition = Vector3.Lerp(transform.position, targetPosition, smoothing * Time.fixedDeltaTime);
transform.position = smoothPosition;
}
}