Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by JohnTheGreek · Jul 24, 2014 at 07:50 AM · 2d-platformer2d-physics2d-sidescroller

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.

Comment
Add comment · Show 12
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Tehnique · Jul 24, 2014 at 07:53 AM 0
Share

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.

avatar image JohnTheGreek Tehnique · Jul 24, 2014 at 07:59 AM 0
Share

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?

avatar image Tehnique Tehnique · Jul 24, 2014 at 08:03 AM 0
Share

It could be they are for Pro, and the asset expects you have the dll alredy referenced.

avatar image JohnTheGreek Tehnique · Jul 24, 2014 at 08:16 AM 0
Share

Actually here is the link for the assets: https://www.assetstore.unity3d.com/en/#!/content/14474

It is not for the pro version.

Show more comments
avatar image DajBuzi · Jul 24, 2014 at 07:57 AM 0
Share

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

avatar image JohnTheGreek · Jul 24, 2014 at 08:12 AM 0
Share

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)

avatar image Tehnique · Jul 24, 2014 at 08:22 AM 0
Share

There is no CrossPlatformInputNamespace, it was just a placeholder for the actual namespace that contains the CrossPlatformInput class, an example.

avatar image JohnTheGreek · Jul 24, 2014 at 08:44 AM 0
Share

So what is the correct namespace? Please be more specific... if you don't know, where could I find the namespace?

3 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

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;
         }
     }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image JohnTheGreek · Jul 24, 2014 at 08:58 AM 0
Share

Thanks, I only imported the 2d folder...

avatar image
7

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image crowladd111 · Feb 20, 2016 at 10:12 AM 0
Share

Thank you so much for this @RedDevil. I had the same problem and I made the adjustment and things are working again

avatar image meat5000 ♦ crowladd111 · Feb 20, 2016 at 10:13 AM 1
Share

Clicking the upvote is a better way to show a good answer.

avatar image
5

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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Idlekas · Aug 18, 2017 at 04:55 PM 0
Share

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.

avatar image Grauen · May 26, 2020 at 08:15 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

I need to shoot a projectile in my 2D platformer in the opposite direction my player is dashing which can be in any direction the player points the joystick 2 Answers

Problem with 2D movment system C#. Keeps moving when no command is given 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges