将旋转应用于主摄像机时,固定操纵杆出现问题。控件是混合的。如何解决此问题?是否需要使用其他类型的操纵杆?我应该在哪里放置“-”?在最前面的数字
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) * sensitivityX;
float pitchAngleChange = (touch.deltaPosition.y / Screen.height) * 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 :(得分:0)
我真的没有收到你的问题,所以我要回答我的两种解释。
如果照相机的旋转方向相反(如果将摇杆向左旋转,则照相机向右旋转),则只需在旋转照相机的速度前面添加一个负号即可。
如果在使用左摇杆而您想使用右摇杆时相机发生旋转。然后,您应该在输入中定义一个名为camera-rotation-x之类的字段,并使用此处文章中以下图片所示的轴:https://gamedev.stackexchange.com/questions/150323/unity3d-how-to-use-controller-joystick-to-look-around如果您遵循该文章,那么您的摄像机旋转就可以了。>