- Home /
The name `CrossPlatformInput' does not exist in the current context
I am trying to make my first 2d platformer but this message pops up whenever I try to enter playmode. Any help? Keep in mind that I am not by any means an expert programmer. Here is the code causing the error below:
using UnityEngine;
[RequireComponent(typeof(PlatformerCharacter2D))]
public class Platformer2DUserControl : MonoBehaviour
{
private PlatformerCharacter2D character;
private bool jump;
void Awake()
{
character = GetComponent<PlatformerCharacter2D>();
}
void Update ()
{
// Read the jump input in Update so button presses aren't missed.
#if CROSS_PLATFORM_INPUT
if (CrossPlatformInput.GetButtonDown("Jump")) jump = true;
#else
if (Input.GetButtonDown("Jump")) jump = true;
#endif
}
void FixedUpdate()
{
// Read the inputs.
bool crouch = Input.GetKey(KeyCode.LeftControl);
#if CROSS_PLATFORM_INPUT
float h = CrossPlatformInput.GetAxis("Horizontal");
#else
float h = Input.GetAxis("Horizontal");
#endif
// Pass all parameters to the character control script.
character.Move( h, crouch , jump );
// Reset the jump input once it has been used.
jump = false;
}
}
UPDATE: I am using the 2d player animator from the free sample 2d assets from the asset store.
You are missing a reference to the dll that contains the "CrossPlatformInput". I can't find much about this class online, but if you got the code from soewhere, be sure you include all the resources that came with it in your project.
I just imported the sample 2d assets from the asset store... I never edited ANY of the code, so why would any resources be missing?
It could be they are for Pro, and the asset expects you have the dll alredy referenced.
Actually here is the link for the assets: https://www.assetstore.unity3d.com/en/#!/content/14474
It is not for the pro version.
Hello, This error means that compiler do not know about CrossPlatformInput, Try adding appropriate namespace or reference if it's not static object like:
using CrossPlatformInputNamespace; //Just for example
//or
using CPInput = CrossPlatformInputNamespace;
This problem can occur if you dont have CrossPlatformInput extension implemented in this project.
Regards, $$anonymous$$.Rogalski
Hello, thanks for the asistance. I tried to add each of these lines in the code but it didn't work. There was a different error saying "The type or namespace name "CrossPlatformInputNamespace" could not be found. Are you missing a using drective or an assembly reference?". So, now what? (btw I understand that this might be a stupid question but as I said I am a n00b programmer)
There is no CrossPlatformInputNamespace, it was just a placeholder for the actual namespace that contains the CrossPlatformInput class, an example.
So what is the correct namespace? Please be more specific... if you don't know, where could I find the namespace?
Answer by duck · Jul 24, 2014 at 08:47 AM
I'm guessing you imported the whole sample assets beta package, then deleted some of the folders? (For example, the "Cross Platform Input" folder?)
If you're not interested in the cross-platform input features provided in the sample assets package (i.e. having touch/tilt controls mapped to Horizontal / Vertical axes, etc) and you've already deleted the "Cross Platform Input" folder, then you can delete those parts from your code which refer to it, leaving you with something that should look like this:
using UnityEngine;
[RequireComponent(typeof(PlatformerCharacter2D))]
public class Platformer2DUserControl : MonoBehaviour
{
private PlatformerCharacter2D character;
private bool jump;
void Awake()
{
character = GetComponent<PlatformerCharacter2D>();
}
void Update ()
{
// Read the jump input in Update so button presses aren't missed.
if (Input.GetButtonDown("Jump")) jump = true;
}
void FixedUpdate()
{
// Read the inputs.
bool crouch = Input.GetKey(KeyCode.LeftControl);
float h = Input.GetAxis("Horizontal");
// Pass all parameters to the character control script.
character.Move( h, crouch , jump );
// Reset the jump input once it has been used.
jump = false;
}
}
Answer by RedDevil · Jul 24, 2014 at 08:48 AM
I see you are using the sample assets.When you imported that script you forgot to import the cross platform folder.
Thank you so much for this @RedDevil. I had the same problem and I made the adjustment and things are working again
Clicking the upvote is a better way to show a good answer.
Answer by Rihcodo · Feb 06, 2017 at 08:26 AM
You Can Solve This Problem Directly By moving new assets folder which you import to new folder i just create folder named Import and move Standard Assets folder to it and every thing work correctly
Following the tutorial, and got same error. in fact 15 of them all similar. I didn't delete any folders and i tried to re-imported asset, but when this was done was told launcher said that all files for this asset were downloaded. Followed this simple advice and was able to move on.
3 Years later and this is still a valid answer.
Can someone explain why this works? Why does unity have so much problems resolving classes and dependencies?
Your answer
![](https://koobas.hobune.stream/wayback/20220613154845im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
The name `PlatformerCharacter2D' does not exist in the current context 1 Answer
2d Sidescroll problem with wall sliding 1 Answer
How do I get the character to jump in a 2d game, which is compatible with joysticks and keyboards? 0 Answers
Problem with 2D movment system C#. Keeps moving when no command is given 0 Answers