前回FPS視点の動きができるような移動系を作成しました。前回のでもかなり十分機能してくれます。
しかし、今回は難しいことを考えずキャラクターの移動はできたけど、視点移動ができないだけなんだ!っていう人向けに解説していきます。
前回の記事はこちら↓
カメラポイントを追従させるようにする

1.今回は[CameraPoint]という名前の空のオブジェクトを追従する形にしていきます。右図のようにオブジェクトを設定。(詳細は上記記事参照)

2.CameraControllerをアタッチし、そこにMaincameraをいれる。
CameraControllerのコードは↓
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
public Transform target;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void LateUpdate()
{
transform.position = target.position;
transform.rotation = target.rotation;
}
}
たったこれだけです。
マウスの表示を消して、ウィンドウ外にでないようにする方法
おまけとして、マウス表示について書いておきます。

GameMnagersを空のオブジェクトで作成し、その子オブジェクトGameMnagerに次のコードをアタッチするだけです。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameManager : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Locked;//マウス表示をウィンドウ外に出さないようにする
}
// Update is called once per frame
void Update()
{
}
}
コメント