19 lines
569 B
C#
19 lines
569 B
C#
using UnityEngine;
|
|
|
|
public class CameraFollow : MonoBehaviour
|
|
{
|
|
public Transform target; // Nhân vật (Player)
|
|
public Vector3 headOffset = new Vector3(0, 1.6f, 0.2f); // Vị trí mắt so với chân nhân vật
|
|
|
|
void LateUpdate()
|
|
{
|
|
if (target == null) return;
|
|
|
|
// Đặt camera ngay tại vị trí "mắt" của nhân vật
|
|
transform.position = target.position + target.TransformDirection(headOffset);
|
|
|
|
// Camera luôn nhìn theo hướng xoay của nhân vật
|
|
transform.rotation = target.rotation;
|
|
}
|
|
}
|