Error... that I don't understand.

I have a very simple script set up, and I am getting two errors. The errors are:

  • Assets/Movement.cs(15,26): error CS1502: The best overloaded method match for 'UnityEngine.Input.GetButton(string)' has some invalid arguments
  • Assets/Movement.cs(15,26): error CS1503: Argument '#1' cannot convert UnityEngine.KeyCode’ expression to type ‘string’`

My script is here:

using UnityEngine;
using System.Collections;

public class Movement : MonoBehaviour {

	public float speed = 4f;

	// Use this for initialization
	void Start () {
	// Update is called once per frame
	void Update () {
		if(Input.GetButton(KeyCode.Space)) {
			transform.Translate(Vector3.up * Time.deltaTime * speed);
		} else {
			transform.Translate(Vector3.down * Time.deltaTime * speed);

Thanks in advance! :smiley:

GetButton takes string not a KeyCode. Name the inputs in the input manager.

Try to change from




In fact Input.GetButton requires a string (e.g. “Space”) as a valid value.

You want Input.GetKey().

if(Input.GetKey(KeyCode.Space)) {

Input.GetButton() returns a named button from your defined Axes and must be passed a string name.