Search Unity

Question Can someone find out whats wrong with this

Discussion in 'Scripting' started by theZking, Dec 14, 2022.

Thread Status:
Not open for further replies.
  1. theZking

    theZking

    Joined:
    Dec 10, 2022
    Posts:
    9
    I've only been coding on Unity for 3 days and I have this problem where I am getting all these errors:
    Assets\SceneChange.cs(25,1): error CS1022: Type or namespace definition, or end-of-file expected
    Assets\SceneChange.cs(21,1): error CS0106: The modifier 'public' is not valid for this item
    Assets\SceneChange.cs(21,1): error CS8803: Top-level statements must precede namespace and type declarations.

    does anyone know how to fix them
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5.  
    6. public class SceneChange : MonoBehaviour
    7. {
    8.     // Start is called before the first frame update
    9.     void Start()
    10.     {
    11.        
    12.     }
    13.  
    14.     // Update is called once per frame
    15.     void Update()
    16.     {
    17.        
    18.     }
    19. }
    20.  
    21. public void ChangeScene()
    22. {
    23.     SceneManager.LoadScene("Career Menu");
    24. }
    25. }
     
  2. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    arkano22 and Bunny83 like this.
  3. BABIA_GameStudio

    BABIA_GameStudio

    Joined:
    Mar 31, 2020
    Posts:
    497
    Seriously? Your previous topic was the exact same issue and you were told that the method was outside of your class.
    If you still do not know what a class is, or why your methods need to be inside your class, then you really need to stop what you are doing and go off to work through a load of beginner C# tutorials.

    Only once you are able to work in C# properly will you really be able to get further in writing Unity scripts (at least without having to come to the forum to ask the same question more times).

    Sorry if this sounds harsh, but it is the reality that you are going to have to face. Programming is something that you have to be 100% accurate in, so you need that understanding first.
     
    Bunny83 likes this.
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    Thread moved to the Scripting forum and closed due to it being a clear duplicate.
     
    Bunny83 likes this.
Thread Status:
Not open for further replies.