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);

    }
}

 

posted @ 2020-05-11 14:27  哎呦不能错喔  阅读(582)  评论(0编辑  收藏  举报