Compile error showing in unity, not showing in Visual Studio

I’m pretty new to Unity and game dev in general, but this problem genuinely makes no sense to me, where as all other problems I’ve encountered so far I’ve been able to solve on my own.

When in the unity editor, I get this error message:

Assets\Scripts\LevelGen\LevelGeneration.cs(90,45): error CS1513: } expected

Here’s my code:

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

public class LevelGeneration : MonoBehaviour
{
    public Transform[] startingPositions;
    public GameObject[] rooms; // index 0 = LR, index 1 = LRB, index 2 = LRT, index 3 = LRBT

    private int direction;
    public float moveAmount;

    private float timeBtwRoom;
    public float startTimeBtwRoom = 0.25f;

    public float minX;
    public float maxX;
    public float minY;
    private bool stopGeneration;

    private void Start()
    {
        int randStartingPos = Random.Range(0, startingPositions.Length);
        transform.position = startingPositions[randStartingPos].position;
        Instantiate(rooms[0], transform.position, Quaternion.identity);

        direction = Random.Range(1, 6);
    }

    private void Update()
    {
        if (timeBtwRoom <= 0 && stopGeneration == false)
        {
            Move();
            timeBtwRoom = startTimeBtwRoom;
        }
        else
        {
            timeBtwRoom -= Time.deltaTime;
        }
    }

    private void Move()
    {
        if (direction == 1 || direction == 2) // move right
        {
            if (transform.position.x < maxX)
            {
                Vector2 newPos = new Vector2(transform.position.x + moveAmount, transform.position.y);
                transform.position = newPos;

                int rand = Random.Range(0, rooms.Length);
                Instantiate(rooms[rand], transform.position, Quaternion.identity);

                direction = Random.Range(1, 6);
            }
            else
            {
                direction = 5;
                if (direction == 3)
                {
                    direction = 2;
                } else if (direction == 4)
                {
                    direction = 5;
                }
            }

        } else if (direction == 3 || direction == 4) // move left
        {
            if (transform.position.x > minX)
            {
                Vector2 newPos = new Vector2(transform.position.x - moveAmount, transform.position.y);
                transform.position = newPos;

                direction = Random.Range(3, 6);
            }
            else
            {
                direction = 5;
            }


        }
        else if (direction == 5) // move down
        {
            if (transform.position.y > minY)
            {
                Vector2 newPos = new Vector2(transform.position.x, transform.position.y - moveAmount);
                transform.position = newPos;

                in rand = Random.Range(2, 4);
                Instantiate(rooms[rand], transform.position, Quaternion.identity);

                direction = Random.Range(1, 6);
            }
            else
            {
                // stop generation
                stopGeneration = true;
            }


        }

        Instantiate(rooms[0], transform.position, Quaternion.identity);

    }
}

I can’t figure out what the issue is, and in visual studio it tells me that there are “no errors found.”

Anybody know what the problem is?

Also credit for the majority of what I’ve learned so far goes to BlackThornProd and his tutorials.

Line 92:

in rand = Random.Range(2, 4);

should read:

int rand = Random.Range(2, 4);
1 Like

Unity is what counts… Visual Studio might not be fully up to date with your project, or there could be another issue.

This may help you with intellisense and possibly other Visual Studio integration problems:

Sometimes the fix is as simple as doing Assets → Open C# Project from Unity. Other times it requires more.

https://discussions.unity.com/t/778503

Also, try update the VSCode package inside of Unity: Window → Package Manager → Search for Visual Studio Code Editor → Press the Update button

Also, this: https://discussions.unity.com/t/805330/7

oh my god…

thank you so much for spotting that. this one missing character has caused me so much agony