Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'CrossPlatformInputManager' does not exist in the current context

So I'm working on a project in Unity and this pops up out of the blue.
The console error is:

Assets/StandardAssets/Vehicles/Aircraft/Scripts/AeroplaneUserControl2Axis.cs(29,27): error CS0103: The name 'CrossPlatformInputManager' does not exist in the current context

The following is the script to which it is referring:

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);
        }
    }
}
like image 457
BrookDaCow Avatar asked Oct 18 '25 09:10

BrookDaCow


2 Answers

Had similar issues and solved it by simply importing the assets. Here are the steps:

  1. Go to Assets->Import Package->CrossPlatformInput
  2. Click on All (or the one which you need)
  3. Click on Import

enter image description here

like image 138
Just Shadow Avatar answered Oct 20 '25 00:10

Just Shadow


Installing the whole Standard Assets package is the probable solution. If you do not want to install the whole StanardAssets module, don't forget to install the Initializer in the Editor folder as shown in the picture.

donot forget Initializer

like image 28
max yi Avatar answered Oct 19 '25 23:10

max yi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!