error CS0119: Expression denotes a 'type', where a 'variable', 'value' or 'method group' was expecte

Heres my code:

using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour
{
    public float speed;

    public float right = KeyCode;
    public float left = KeyCode;

    void FixedUpdate ()
    {
        if(Input.GetKey(right))
        {
            rigidbody2D.velocity.x = speed;
        }
        else if(Input.GetKey (left))
        {
            rigidbody2D.velocity.x = speed*-1;
        }
        else
        {
            rigidbody2D.velocity.x = 0;
        }
    }
}

I don’t know why i am getting the error i have tried looking around on google but nothing seems to help me.

Thanks in advance for any help!

In C# you can’t just set the individual part of the vector like that. you need to do something like:

rigidbody2D.velocity = newVector2 (speed, rigidbody2D.velocity.y);

I am a complete beginner, how would you put that into my code?

Line 8 and 9 make no sense.

8 is probably meant like that:

public Keycode right = KeyCode.RightArrow;

:frowning: I am really confused i am trying to make a script for a snappy platformer where when you let go of the key the character just stops, I havent found a single way to do this :frowning:

There are a lot of resources online where you can learn how to code in Unity. This one is pretty good:

It is not specifically for 2D, but you will learn lots of basics that will help you later on.