0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Playerが動く方向にカメラも動く方法

Posted at
CameraManager
public class CameraManager : MonoBehaviour
{
    //格納する変数
    public GameObject Player;
    public float CameraX;
    public float CameraY;
    public float CameraZ;

    void Start()
    {

    }

    void Update()
    {

        Vector3 Pos = Player.transform.position;

        //カメラとプレイヤーの位置を同じにする
        transform.position = new Vector3(Pos.x + CameraX, Pos.y + CameraY, Pos.z + CameraZ);
    }
}

ここまで書けたらカメラにスクリプトをアタッチ。
インスペクターにある
CameraX
CameraY
CameraZ
にはPlayerとカメラの位置を設定する。

PlayerにはヒエラルキーのPlayerを入れる。
(私の場合はPlayerですが、カメラで追いかけたいものを紐づける)

これでPlayerが動くと同時にカメラが追いかけるようになりました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?