`Input' does not contain a definition for `GetAxis'

Hello everyone!

I have been a unity3D user for several years now, and I have developed a decent ability with C# scripting inside the engine.

Just recently, I have encountered this error while scripting:

‘Input’ does not contain a definition for ‘GetAxis’

The same goes for any other input definitions.

I have no clue what is wrong. When using MonoDevelop, the only definitions available in Input are those that belong to Object/GameObject.

I am sure that this isn’t a problem with any script I have, as it is currently just a copy of an example from the scripting reference, additionally, the script was working fine for several test beforehand.

Any tips would be greatly appreciated!

3 Answers

3

Don’t name your classes the same thing as Unity classes. (Well, you can, but if you do that then you have to specify which one you mean every time, which is a bit annoying.)

Creating a javascript with the name Input would do the same thing, it makes a class called Input.

–

You made a class called Input, which doesn't have a GetAxis function, so when you say "Input.GetAxis", Unity looks in your Input class and doesn't find any GetAxis function, and complains. You can differentiate by saying "UnityEngine.Input", but as I said, it's better just to not do that.

–

To be clear - you haven't made a script called Input in Javascript? It's got to be that or the fact you have created a variable called Input which is of type GameObject.

–

Yep, it's usually the smart thing to do :p

–

For anybody else, who maybe more recently than 2 years ago encountered this problem. I just fixed mine with: changing float moveHorizontal = Input.getAxis(“Horizontal”); to

{
float moveHorizontal = UnityEngine.Input.GetAxis(“Horizontal”);
}

It doens’t recognize the getAxis without a CAPital G and it doesn’t recognize the Input without UnityEngine attached.

You would never use getAxis anyway since functions are always capitalized. But yes, doing this is exactly what I said to do in my answer. All of this has already been explained (read the comments).

–

I just had this problem and I spelt axes instead of axis