Unity 模仿scene视图相机视角移动

Posted feiyuzhu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unity 模仿scene视图相机视角移动相关的知识,希望对你有一定的参考价值。

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

public class Cam : MonoBehaviour
{
    void Start()
    {

    }

    void Update()
    {
        if (Input.GetMouseButton(1))
        {
            float x = Input.GetAxis("Mouse X");
            float y = Input.GetAxis("Mouse Y");
            transform.Rotate(new Vector3(-y, x)*3);

            Vector3 v = transform.localEulerAngles;
            transform.localEulerAngles = new Vector3(v.x,v.y,0);
        }

        if (Input.GetMouseButton(0))
        {
            float x = Input.GetAxis("Mouse X");
            float y = Input.GetAxis("Mouse Y");
            transform.Translate(new Vector3(-x, -y));
        }

        transform.Translate(Vector3.forward*Input.GetAxis("Mouse ScrollWheel")*3);

    }
}

 

以上是关于Unity 模仿scene视图相机视角移动的主要内容,如果未能解决你的问题,请参考以下文章