Files
Fishing2/Assets/UnityStandardAssets/Vehicles/Aeroplane/AeroplaneUserControl4Axis.cs
2025-05-10 12:49:47 +08:00

46 lines
1.3 KiB
C#

using System;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
namespace UnityStandardAssets.Vehicles.Aeroplane
{
[RequireComponent(typeof(AeroplaneController))]
public class AeroplaneUserControl4Axis : MonoBehaviour
{
public float maxRollAngle = 80f;
public float maxPitchAngle = 80f;
private AeroplaneController m_Aeroplane;
private float m_Throttle;
private bool m_AirBrakes;
private float m_Yaw;
private void Awake()
{
m_Aeroplane = GetComponent<AeroplaneController>();
}
private void FixedUpdate()
{
float axis = CrossPlatformInputManager.GetAxis("Mouse X");
float axis2 = CrossPlatformInputManager.GetAxis("Mouse Y");
m_AirBrakes = CrossPlatformInputManager.GetButton("Fire1");
m_Yaw = CrossPlatformInputManager.GetAxis("Horizontal");
m_Throttle = CrossPlatformInputManager.GetAxis("Vertical");
m_Aeroplane.Move(axis, axis2, m_Yaw, m_Throttle, m_AirBrakes);
}
private void AdjustInputForMobileControls(ref float roll, ref float pitch, ref float throttle)
{
float num = roll * maxRollAngle * ((float)Math.PI / 180f);
float num2 = pitch * maxPitchAngle * ((float)Math.PI / 180f);
roll = Mathf.Clamp(num - m_Aeroplane.RollAngle, -1f, 1f);
pitch = Mathf.Clamp(num2 - m_Aeroplane.PitchAngle, -1f, 1f);
}
}
}