Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Error CS1022

Discussion in 'Editor & General Support' started by PlanetofLinux, Jun 15, 2015.

  1. PlanetofLinux

    PlanetofLinux

    Joined:
    Jun 15, 2015
    Posts:
    2
    So i was on youtube seeing a tutorial of how to make a platformer unity game i did this code and it dosen't seem to work

    using UnityEngine;
    using System.Collections;

    public class PlayerController : MonoBehaviour {

    public float moveSpeed;
    public float jumpHeight;

    // Use this for initialization
    void Start () {

    }

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

    if (Input.GetKeyDown) (KeyCode.Space)
    [
    GetComponent<Rigidbody2D>().velocity = new Vector2 {1, jumpHeight};

    }
    }
    }
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,559
    Your code was formatted wrong and did not properly close all braces. This should work:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerController : MonoBehaviour
    5. {
    6.     public float moveSpeed;
    7.     public float jumpHeight;
    8.  
    9.     // Use this for initialization
    10.     void Start ()
    11.     {
    12.     }
    13.  
    14.     // Update is called once per frame
    15.     void Update ()
    16.     {
    17.         if (Input.GetKeyDown) (KeyCode.Space)
    18.         {
    19.             GetComponent<Rigidbody2D>().velocity = new Vector2 {1, jumpHeight};
    20.         }
    21.     }
    22. }
     
  3. PlanetofLinux

    PlanetofLinux

    Joined:
    Jun 15, 2015
    Posts:
    2
    It says unexpected symbol {
     
    Last edited: Jun 21, 2015