1
1

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 5 years have passed since last update.

マウスクリックでカメラを回転・リセット

Posted at

ポジションは変わらずに、その場所を中心にカメラを回転させる

GameObjectの中にカメラを配置
以下のスクリプトでGameObject自体を回転させる

CameraAxis.cs
using UnityEngine;
using System.Collections;

public class CameraAxis : MonoBehaviour
{
    public float fRotateSpeed = 10.0f;

    void Update()
    {
        // 左
        bool canRotateLeft = Input.GetMouseButton(0);
        // 右
        bool canRotateRight = Input.GetMouseButton(1);
        // 中
        bool canResetPos = Input.GetMouseButton(2);

        if (canRotateLeft)
        {
            // 移動量 
            float fValue = fRotateSpeed * Time.deltaTime;
            // 回転 
            transform.Rotate(0, -fValue, 0, Space.World);
        }
        if (canRotateRight)
        {
            float fValue = fRotateSpeed * Time.deltaTime;
            transform.Rotate(0, fValue, 0, Space.World);
        }
        if (canResetPos)
        {
            transform.localRotation = Quaternion.identity;
        }
    }
}

参考
079 GameObjectを中心にカメラを回転させる
Unityでマウス入力を扱う
Unityメモ – Transformにリセット処理を追加してみる

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?