• unity中鼠标左键控制摄像机视角上下左右移动


    enum RotationAxes { MouseXAndY, MouseX, MouseY }
    RotationAxes axes = RotationAxes.MouseXAndY;
    //@HideInInspector
    float sensitivityX = 15;
    //@HideInInspector
    float sensitivityY = 15;
    //private float minimumX = -360; 原文有此行但并未使用此变量
    //private float maximumX = 360; 同上
    float minimumY = -80;
    float maximumY = 80;
    private float rotationY = 0;
    // Use this for initialization
    void Start()
    {
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            if (axes == RotationAxes.MouseXAndY)
            {
                float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
                rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
                rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
                transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
            }
            else if (axes == RotationAxes.MouseX)
            {
                transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
            }
            else
            {
                rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
                rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
                transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
            }
        }
    }
  • 相关阅读:
    【如何入门ACM】
    HDU
    HDU 6107 Typesetting
    bzoj 3223: Tyvj 1729 文艺平衡树
    51Nod 1781 跑的比谁都快
    51Nod 1331 狭窄的通道
    51Nod 1555 布丁怪
    hihocoder 1035 : 自驾旅行 III
    51Nod 1196 字符串的数量
    51Nod 1530 稳定方块
  • 原文地址:https://www.cnblogs.com/Study088/p/7892528.html
Copyright © 2020-2023  润新知