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

Error CS1519: Invalid token 'void' in class, struct, or interface member declaration

Discussion in '2D' started by ajmracer032706, Sep 15, 2020.

  1. ajmracer032706

    ajmracer032706

    Joined:
    Sep 15, 2020
    Posts:
    24
    I am trying to put together some level reset code and I keep getting this error. I have tried uninstalling Visual Studio a few times and nothing is working. I have even created new scripts and the problem still remains. Here is the code:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class Game : MonoBehaviour
    {
    private scene
    // Start is called before the first frame update
    void Start()
    {
    scene = SceneManager.GetActiveScene();
    }
    void OnTriggerEnter2D(Collider2D col)
    {
    if (col.gameObject.tag == "Respawn")
    {
    Application.LoadLevel(scene.name);
    }
    }
    }
    All help is appreciated, thanks!
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,343
    This isn't a 2D features problem so isn't for this forum. Anyway, given that you've reinstalled visual studio for what is just incorrect code typed I guess you're new to C# as this is a C# compiler error indicating you typed something wrong.

    The error will tell you what line the error is on and you can search for that error (CS1519).

    You've got "private scene" on a line which is incomplete. The next thing the compiler sees is "void Start()" so it's saying it saw "void" unexpected i.e. invalid.

    It looks like you meant to put "private Scene scene;" (note the capital).

    "Scene" is the type. "scene" if your variable name.
     
  3. ajmracer032706

    ajmracer032706

    Joined:
    Sep 15, 2020
    Posts:
    24
    Ok I will try this. I had it before and it still didn't work right. Will give it another shot.
     
    MelvMay likes this.