(Unity6 BRP)シンプルなカーレースゲームの作成(追従カメラ)

(サンプルコード)

using UnityEngine;

public class CameraFollow : MonoBehaviour
{
    public Transform target;
    public Vector3 offset = new Vector3(0, 5, -8);

    private void LateUpdate()
    {
        if(!target)
        {
            return;
        }

        Vector3 desiredPosition = target.position + target.rotation * offset;

        transform.position = desiredPosition;

        transform.LookAt(target);
    }
}

(実行結果)