20 lines
503 B
C#
20 lines
503 B
C#
using UnityEngine;
|
|
|
|
public class CameraFollow : MonoBehaviour
|
|
{
|
|
public Transform target; // The player's transform to follow
|
|
public Vector3 offset = new Vector3(0f, 2f, -5f); // Offset from the target
|
|
|
|
void Update()
|
|
{
|
|
if (target == null)
|
|
return;
|
|
|
|
// Update the camera's position to follow the target with an offset
|
|
transform.position = target.position + offset;
|
|
|
|
// Make the camera look at the target
|
|
transform.LookAt(target);
|
|
}
|
|
}
|