外观旋转相机干扰操纵杆控件

时间:2019-06-02 07:06:03

标签: unity3d

我制作此视频以更好地理解我要解释的内容。因此,外观旋转脚本插入了操纵杆控件。无论我移动相机转动多少,我都可以使后退,后退前进。 https://streamable.com/h20rs

using System.Collections.Generic;
using UnityEngine;

[AddComponentMenu("Camera-Control/Mouse Look")]
public class MouseLook : MonoBehaviour
{

    public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
    public RotationAxes axes = RotationAxes.MouseXAndY;
    public float sensitivityX = 15F;
    public float sensitivityY = 15F;

    public float minimumX = -360F;
    public float maximumX = 360F;

    public float minimumY = -60F;
    public float maximumY = 60F;

    float rotationY = 0F;

    void Update()
    {
        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);
            float turnAngleChange = (touch.deltaPosition.x / Screen.width)*-1f * sensitivityX;
            float pitchAngleChange = (touch.deltaPosition.y / Screen.height)*-1f * sensitivityY;

            // Handle any pitch rotation
            if (axes == RotationAxes.MouseXAndY || axes == RotationAxes.MouseY)
            {
                rotationY = Mathf.Clamp(rotationY + pitchAngleChange, minimumY, maximumY);
                transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0f);
            }

            // Handle any turn rotation
            if (axes == RotationAxes.MouseXAndY || axes == RotationAxes.MouseX)
            {
                transform.Rotate(0f, turnAngleChange, 0f);
            }
        }

        void Start()
        {
            //if(!networkView.isMine)
            //enabled = false;

            // Make the rigid body not change rotation
            //if (rigidbody)
            //rigidbody.freezeRotation = true;
        }
    }
}

对于操纵杆,我下载了资产。

0 个答案:

没有答案