CS1513 Error. Checked Code for missing braces, can't find any

Been making a Subway Surfer Clone to get into using unity. Stumbled into an cs1513 error i can’t resolve, checked the whole code for missing braces but I can’t find any. I also never created a function that returns a value, so I might be missing smth in that context.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpawnManager : MonoBehaviour
    public GameObject[] obstaclePrefab;
    // Base Speed modified over Time to increase difficulty
    public float speed;
    public float increaseDifficultyTime;
    private float increaseDifficultyStart;

    // Define minimum distance percentage between spawnable Objects ( will be used in relation to speed)
    private float[] spawnTime = {0, 0, 0};
    private float[] spawnLane = {0, 1, 2};
    private int randomObstacle;
    private float[] obstacleSpawnHeight = {1f, 2.1f, 2f, 2.2f};
    private Vector3 spawnPos;

    // Minimum time between different object Spawns, train lengths etc.
    public float minSpawnCooldown = 1f;
    private int trainLength;
    private float trainCarOffset = 15.5f;
    private float trainCarTimeOffset = 0.775f;
    public float[] trainStillOnLane = {0, 0, 0};

    // Game Over check variables
    public PlayerController playerControllerScript;
    // Start is called before the first frame update
    void Start()
        playerControllerScript = GameObject.Find("Player").GetComponent<PlayerController>();
        increaseDifficultyStart = increaseDifficultyTime;

    // Update is called once per frame
    void Update()
        if (playerControllerScript.gameOver == false) {
        if (Time.time > increaseDifficultyStart) {

    // Creates an Obstacle
    void createObstacle() {
        foreach (int lane in spawnLane) {
            if (Time.time > spawnTime[lane]) {
                // Choose a Random Obstacle with an addition of 1 to obstaclePrefabs length
                randomObstacle = Random.Range(0, obstaclePrefab.Length + 3);
                // Adds the ability to not add an obstacle
                if (randomObstacle < 4) {
                    // If the Obstacle is a train car, get a random number between 1 and 3 to decide the trains length.
                    if (randomObstacle == 3 && checkLanesForTrains() == true) {
                        // Decide on the Length of the train
                        trainLength = Random.Range(1, 4);
                        for (int i = 0; i < trainLength; i++) {
                            spawnPos = new Vector3 (transform.position.x + (trainCarOffset * i), obstacleSpawnHeight[randomObstacle], (spawnLane[lane] - 1f) * 3);
                            Instantiate(obstaclePrefab[randomObstacle], spawnPos, transform.rotation);
                        // Set the spawntime on the lane and the value to check if the lane is still occupied for the checkLanesForTrains function
                        spawnTime[lane] = Time.time + (trainLength * trainCarTimeOffset) + minSpawnCooldown;
                        trainStillOnLane[lane] = spawnTime[lane];
                    } else {
                        spawnPos = new Vector3 (transform.position.x, obstacleSpawnHeight[randomObstacle], (spawnLane[lane] - 1f) * 3);
                        Instantiate(obstaclePrefab[randomObstacle], spawnPos, transform.rotation);
                        spawnTime[lane] = Time.time + minSpawnCooldown;

    // Checks if two lanes are currently occupied by trains and returns false if this is the case
    public bool checkLanesForTrains() {
        private int occupied = 0;
        foreach (int trainLane in spawnLanes) {
            if (Time.time < trainStillOnLane[trainLane]) {
                occupied ++;
        if (occupied > 1) {
            return (false);
        } else {
            return (true);

    void increaseDifficulty() {
        speed *= 1.1f;
        increaseDifficultyStart = Time.time + increaseDifficultyTime;

These are The Errors I get:

Your error is in this line:

public bool checkLanesForTrains() {
        private int occupied = 0;

and points to the very end of the first of those two lines. So why do you think it may suggest that you should add a closing brace right at the end, even though you just opened one?

Right, the reason is the very next thing which is private. Access modifiers can only be used in type declarations (inside a class, interface or struct). Since you just entered a method body the compiler suggests to close the method first before you declare a member field in the class. Of course that’s not what you wanted to do, but the compiler reads your code top to bottom, left to right.

So remove that private and the error(s) should be resolved. Though I haven’t looked for additional issues.