“CrossPlatformInputManager”在当前上下文中不存在。

4

我正在使用Unity开发一个项目,突然出现了以下控制台错误信息:

Assets/StandardAssets/Vehicles/Aircraft/Scripts/AeroplaneUserControl2Axis.cs(29,27): error CS0103: 当前上下文中不存在“CrossPlatformInputManager”名称

错误是由以下脚本引起的:

using System;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;

namespace UnityStandardAssets.Vehicles.Aeroplane
{
    [RequireComponent(typeof (AeroplaneController))]
    public class AeroplaneUserControl2Axis : MonoBehaviour
    {
        // these max angles are only used on mobile, due to the way pitch   and roll input are handled
        public float maxRollAngle = 80;
        public float maxPitchAngle = 80;

        // reference to the aeroplane that we're controlling
        private AeroplaneController m_Aeroplane;


        private void Awake()
        {
            // Set up the reference to the aeroplane controller.
            m_Aeroplane = GetComponent<AeroplaneController>();
        }


        private void FixedUpdate()
        {
            // Read input for the pitch, yaw, roll and throttle of the aeroplane.
            float roll = CrossPlatformInputManager.GetAxis("Horizontal");
            float pitch = CrossPlatformInputManager.GetAxis("Vertical");
            bool airBrakes = CrossPlatformInputManager.GetButton("Fire1");

            // auto throttle up, or down if braking.
            float throttle = airBrakes ? -1 : 1;
#if MOBILE_INPUT
            AdjustInputForMobileControls(ref roll, ref pitch, ref throttle);
#endif
            // Pass the input to the aeroplane
            m_Aeroplane.Move(roll, pitch, 0, throttle, airBrakes);
        }


        private void AdjustInputForMobileControls(ref float roll, ref float      pitch, ref float throttle)
        {
            // because mobile tilt is used for roll and pitch, we help out by
            // assuming that a centered level device means the user
            // wants to fly straight and level!

            // this means on mobile, the input represents the *desired* roll angle of the aeroplane,
            // and the roll input is calculated to achieve that.
            // whereas on non-mobile, the input directly controls the roll of the aeroplane.

            float intendedRollAngle = roll*maxRollAngle*Mathf.Deg2Rad;
            float intendedPitchAngle = pitch*maxPitchAngle*Mathf.Deg2Rad;
            roll = Mathf.Clamp((intendedRollAngle - m_Aeroplane.RollAngle),     -1, 1);
            pitch = Mathf.Clamp((intendedPitchAngle -   m_Aeroplane.PitchAngle), -1, 1);

            // similarly, the throttle axis input is considered to be the     desired absolute value, not a relative change to current throttle.
            float intendedThrottle = throttle*0.5f + 0.5f;
            throttle = Mathf.Clamp(intendedThrottle - m_Aeroplane.Throttle,     -1, 1);
        }
    }
}
5个回答

4
我遇到了类似的问题,通过导入资产来解决。以下是步骤:
  1. 进入 Assets->Import Package->CrossPlatformInput
  2. 点击 All(或需要的那个)
  3. 点击 Import

enter image description here


2
安装整个标准资源包是可能的解决方案。如果您不想安装整个StandardAssets模块,请不要忘记按照图片中所示,在Editor文件夹中安装Initializer。

donot forget Initializer


1

我认为您没有StandardAssets模块。运行Unity安装程序并安装StandardAssets包。


那没有解决问题。我仍然有相同的错误。 - BrookDaCow

1

即使导入标准资产后,CrossPlatformInputManager 也显示不存在。你需要做的唯一事情是在Vs Code中安装C# Extention, Ai-Snippetsunity code snippets

我用这个方法解决了我的问题。


0

展开标准资产文件夹,右键单击crossplatforminput文件夹,选择导入包并安装该包。转到您的脚本,在顶部添加using UnityStandardAssets;


在你的代码中添加这一行:using UnityStandardAssets.CrossPlatformInput - baponkar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接