follow cam unity code example
Example: unity camera follow
using UnityEngine;
public class Level3CameraFollow : MonoBehaviour
{
public Transform Target;
public Transform camTransform;
public Vector3 Offset;
public float SmoothTime = 0.3f;
private Vector3 velocity = Vector3.zero;
private void Start()
{
Offset = camTransform.position - Target.position;
}
private void LateUpdate()
{
Vector3 targetPosition = Target.position + Offset;
camTransform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, SmoothTime);
transform.LookAt(Target);
}
}