Please tell me what is wrong with this simple script.

function Update ()
{
if(Input.GetButtonDown(KeyCode.Space))
{
trasform.position.z +=1.0;
}

}

BCE0017: The best overload for the method ‘UnityEngine.Input.GetButtonDown(String)’ is not compatible with the argument list ‘(UnityEngine.KeyCode)’.

Hi,

Input.GetButtonDown expects a parameter that is a string, which is the name of a button as defined in the Input Manager. Click Edit/Project Settings/Input and you will see the Input Manager settings in the Inspector. There, you will see all Input Axes defined, along with their assigned names, and corresponding buttons. The Jump axis is assigned (by default) the name “Jump”, and corresponds to the Space key (i.e. Positive Button).

However, instead of a string (for the GetButtonDown() parameter), you supply KeyCode.Space, which returns an enumeration, and hence error BCE0017.

As far as I know, you would get the excepted result by using ether

Input.GetKeyDown(…) (see Unity - Scripting API: Input.GetKeyDown)

or with the function Input.GetKey(…) (see Unity - Scripting API: Input.GetKey)

Use the first one if you just want to transform it when you first press the button.
With the second funtion, the Transformation will be performed every Frame the button is pressed.

Greetings
Markus

As Markus mentioned, you were probably looking for the other functions.

The function you are using is looking for the strings (strings are words like “apple”, “jump”, and are surrounded by double quotes) that connect up with Unity’s input system.

To find these words and change the input system to your preferences go to:

Edit > Project Settings > Input

and open up the “Axes” group in the inspector. You will see a bunch of default buttons, these are what you use with

Input.GetButtonDown

An example for space is to use the jump key, which is mapped to space. If you open up the first “Jump” under “Axes” you will find the positive button is “space”. To use:

if (Input.GetButtonDown("Jump") == true)
{
    // do some code
}