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. Dismiss Notice

Unexpected symbol `void' in class, struct, or interface member declaration

Discussion in 'Scripting' started by arumiat, Jun 29, 2014.

  1. arumiat

    arumiat

    Joined:
    Apr 26, 2014
    Posts:
    321
    Hi guys

    A noob that is having fun learning C sharp. Please help with my current issue. I'm getting this error message

    Assets/Player1Movement.cs(9,12): error CS1519: Unexpected symbol `void' in class, struct, or interface member declaration

    I have a C sharp script attached to an empty game object.
    The game object has the main camera as a child.
    By moving the game object I'm wanting to move the camera view.

    The below script worked (could move the camera view left, right, up and down) up until the point when I added in the space key to move the gameobject to a new vector 3 position (I initially wanted to translate the camera view forward (zoom) but this is a bit beyond me at the moment!). I'm sure it's something with a very simple fix, but I'm not sure what despite a lot of tinkering. Your help would be much appreciated.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Player1Movement : MonoBehaviour {
    5.  
    6.     float speed = 2.0f
    7.  
    8.     // Use this for initialization
    9.     void Start () {
    10.         transform.position = new Vector3 (0, 0, 0);
    11.     }
    12.  
    13.     // Update is called once per frame
    14.     void Update () {
    15.  
    16.  
    17.         // transform object position using space bar
    18.  
    19.         if (Input.GetKeyDown (KeyCode.Space)){
    20.             transform.position = new Vector3 (0, 5, 0);
    21.         }
    22.  
    23.         // move object up down left right using arrow keys
    24.          if (Input.GetKeyDown(KeyCode.LeftArrow))
    25.         {
    26.             Vector3 position = this.transform.position;
    27.             position.x--;
    28.             this.transform.position = position;
    29.         }
    30.         if (Input.GetKeyDown(KeyCode.RightArrow))
    31.         {
    32.             Vector3 position = this.transform.position;
    33.             position.x++;
    34.             this.transform.position = position;
    35.         }
    36.         if (Input.GetKeyDown(KeyCode.UpArrow))
    37.         {
    38.             Vector3 position = this.transform.position;
    39.             position.y++;
    40.             this.transform.position = position;
    41.         }
    42.         if (Input.GetKeyDown(KeyCode.DownArrow))
    43.         {
    44.             Vector3 position = this.transform.position;
    45.             position.y--;
    46.             this.transform.position = position;
    47.         }
    48.  
    49.     }
    50. }
    51.  
     
    Last edited: Jun 29, 2014
  2. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    You are missing the semicolon on line 6.
     
  3. arumiat

    arumiat

    Joined:
    Apr 26, 2014
    Posts:
    321
    how idiotic, thanks