カメラをTPS(3人称)視点にする

カメラをプレイヤーキャラに追従させてTPS(3人称)にしよう

監視したいプレイヤーをpublicで持たせておいて、Updateごとに追従するようにしましょう。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TPSCamera : MonoBehaviour {

	public GameObject player;//プレイヤーを設定する
	public Vector3 offset = new Vector3(0, 3f, -3f);//プレヤーとカメラの位置関係

	void Update () {

		//プレイヤーの位置にカメラを移動
		transform.position = player.transform.position;

		//プレイヤーの向いている方向にカメラを向ける
		transform.rotation = player.transform.rotation;

		//プレヤーとカメラの位置関係を調整
		transform.Translate (offset);

		//プレイヤーの方向にカメラを向ける
		transform.LookAt (player.transform);
	}
}

あとはカメラにスクリプトをアタッチし、PlayerやOffsetに目的の値を反映させましょう。