プレーヤーの後ろについていくカメラを、スクリプトで作ってみましょう。
プレーヤーとの距離を一定に保ち、動きに応じて、MainCameraも移動していきます。

関連記事:
MainCameraがオブジェクトを追従
シーンを遷移してもカメラ追従を保持する
カメラを旋回しながら自動追従させる
レイヤーによるMainCameraの非表示
MainCameraで四方向から撮影
Vector3.Lerpによる等速移動
Cubeを作成します。
MainCameraを適当なところに配置します。

ゲームビューではこのように見えています。

CubeMove.csを作成し、Cubeに追加します。

CubeMove.csを記述します。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | using System.Collections; using System.Collections.Generic; using UnityEngine; public class CubeMove : MonoBehaviour {     float speed = 3.0f;     void Update()     {         float moveX = Input.GetAxis("Horizontal") * Time.deltaTime * speed;         float moveZ = Input.GetAxis("Vertical") * Time.deltaTime * speed;         transform.position = new Vector3         (             transform.position.x + moveX,              transform.position.y,              transform.position.z + moveZ         );     } } | 
続いて、CameraFollow.csを作成し、MainCameraに追加します。

CameraFollow.csを記述します。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | using System.Collections; using System.Collections.Generic; using UnityEngine; public class CameraFollow : MonoBehaviour {     public GameObject cube;     Vector3 offset;     float speed = 10.0f;     void Start()     {         offset = cube.transform.position - transform.position;     }     void Update()     {         Vector3 newPos = cube.transform.position - offset;         transform.position = Vector3.Lerp(transform.position, newPos, speed * Time.deltaTime);     } } | 
キューブのフィールドに、Cubeを入れます。

ゲームプレイして、十字キー操作しましょう。
距離を保ちながら、Cubeを追いかけて撮影します。

CubeからMainCameraの距離を求め、offsetに格納。
Cubeから、offsetの分だけ離れた位置(newPos)に向けて、カメラを等速移動させています。
関連記事:
MainCameraがオブジェクトを追従
シーンを遷移してもカメラ追従を保持する
カメラを旋回しながら自動追従させる
レイヤーによるMainCameraの非表示
 
	   
         
         
           
         
           
        