Skip to main content
2 of 2
added 100 characters in body
Yecats
  • 131
  • 4

First, @peethor is correct in the comments. Your semi-colon is in the incorrect spot. (Should be at the end of the line. Also, your if statement syntax is incorrect.

Second, you need to get the component of the RigidBody2D before trying to set the velocity. (Make sure that the component exists on the same gameobject that this script is on. If not, you'll have to find the gameobject before getting the component.)

    public float moveSpeed;
    public float jumpHeight;
    private RigidBody2D rb;     
    // Use this for initialization
    void Start () {
        rb = GetComponent<Rigidbody2D>(); //Store a reference to it since you'll access it every update.
    }

    // Update is called once per frame
    void Update () {

        if (Input.GetKeyDown(KeyCode.Space))
        {
            rb.velocity = new vector2(0,jumpHeight);
        }
    }
Yecats
  • 131
  • 4