Visual Studio is giving me an error

Visual Studio is giving me the error: Feature ‘top-level statements’ is not available in C# 8.0. Please use language version 9.0 or greater.
How do I update my C# version?

Here’s my code:

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

public class NumberWizard : MonoBehaviour { }


    int max = 1000;
    int min = 1;
    int guess = 500;

{
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("Welcome to Number Wizard!");
        Debug.Log("Pick a number, but don't tell me what it is...");
        Debug.Log("The highest number you can pick is: " + max);
        Debug.Log("The lowest number you can pick is " + min);
        Debug.Log("Tell my if your number is higher or lower than 500");
        Debug.Log("Push Up = Higher, Push Down = Lower, Push Enter = Correct");
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.UpArrow)) 
        { 
            Debug.Log("Up Arrow key was pressed.");
        }

        else if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            Debug.Log("Down Arrow key was pressed.");
        }

        else if (Input.GetKeyDown(KeyCode.Return))
        {
            Debug.Log("You hit enter.");
        }
    }
}

Hi,

Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture? If not, do that, please. Make sure that the curly brackets are at the correct position. The class code-block must wrap all variables and methods. The variables and methods must not be outside a class code-block.

Did this help?


See also:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms