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

"Unexpected Symbol: '{'"

Discussion in 'Scripting' started by Dev_23, Aug 3, 2015.

  1. Dev_23

    Dev_23

    Joined:
    Oct 4, 2014
    Posts:
    18
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerMovement : MonoBehaviour {
    5.  
    6.     public float speed;
    7.  
    8.     void Update () {
    9.         Move();
    10.     }
    11.  
    12.     void Move() {
    13.         if (Input.GetKey (KeyCode.D) || Input.GetKey (KeyCode.RightArrow)) {
    14.             transform.Translate (Vector2.right * speed * Time.deltaTime);
    15.  
    16.         } else if (Input.GetKey (KeyCode.A || Input.GetKey (KeyCode.LeftArrow)) {
    17.             transform.Translate (Vector2.left * speed * Time.deltaTime);
    18.  
    19.         } [B]else if [/B](Input.GetKey (KeyCode.W) || Input.GetKey (KeyCode.UpArrow)) {  //This else if here has a red underline in the editor
    20.             Jump();
    21.         }
    22.     }
    23.  
    24.     void Jump() {
    25.  
    26.     }
    27. }
    28.  
    This is the error:


    The bolded part has a red underline in MonoDevelop and I can't figure out why. As far as I can tell, all of the braces are pairs...

    Also, the Input.GetKey (KeyCode.LeftArrow) doesn't let my character move left with the left, but it allows A to be used. Any help would be appreciated.
     
  2. Polymorphik

    Polymorphik

    Joined:
    Jul 25, 2014
    Posts:
    599
    Line 16 KeyCode.A you need to close the Parenthesis.
     
  3. Dev_23

    Dev_23

    Joined:
    Oct 4, 2014
    Posts:
    18
    Ah. Thank you!