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?

Unity: Game Viewで視点 (メインカメラ) を移動させる

Last updated at Posted at 2024-09-22

背景

Unityで作ったアプリを起動した際、どのように画面が見えるかは毎回アプリを立ち上げて確認していました。
それだと面倒なので、Game Viewで確認したいと思ったのですが、Game Viewでは視点 (カメラ)を移動できず困ったので、対応した時の覚書です。

Game Viewでメインカメラを移動する

  • 通常はGame Viewで視点(カメラを移動できない)
  • Game Viewで視点を移動する方法の1つとして、スクリプトを書いてメインカメラにAttachする

サンプル例

using UnityEngine;

public class CameraMovement : MonoBehaviour
{
    public float speed = 10f;

    // Update is called once per frame
    void Update()
    {
        // More frames are processed per second on higher performance hardware.
        // By multiplying Time.deltaTime, which is the time took to complate the last frame, makes movement independent from the number of frames per second
        float horizontal = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
        float vertical = Input.GetAxis("Vertical") * speed * Time.deltaTime;
        float scroll = Input.GetAxis("Mouse ScrollWheel")  * speed * Time.deltaTime;      

        // x is horizonta, y is vertical and z is zoom
        transform.Translate(horizontal, vertical, scroll); 
    }
}   
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?