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

Question Followed a tutorial on a Level Loader and now i have 5 errors

Discussion in 'Scripting' started by Mistycal, Feb 8, 2021.

  1. Mistycal

    Mistycal

    Joined:
    Feb 8, 2021
    Posts:
    6
    I followed a tutorial but i think the code is old or something i barely know about scripting and im currently making a game for my school project and i have 5 errors and dont know what to do. Here is the script:

    Code (CSharp):
    1. using System
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.SceneManager;
    6.  
    7. public static class LevelLoader{
    8.  
    9.     public enum Scene {
    10.         Loovtöö 2.0,
    11.         Loading
    12.     }
    13.  
    14.     private static Action onLoaderCallback;
    15.  
    16.     public static void Load(Scene scene) {
    17.         // Set the loader callback action to load the target scene
    18.         onLoaderCallback = () => {
    19.            SceneManager.LoadScene(scene.ToString());
    20.         }
    21.  
    22.         // Load the loading scene
    23.         SceneManager.LoadScene(Scene.Loading.ToString())
    24.     }      
    25.  
    26.     public static void LoaderCallback() {
    27.         // Triggered after the first Update which lets the screen refresh
    28.         // Execute the loader callback action which will load the target scene
    29.         if (onLoaderCallback !=null) {
    30.             onLoaderCallback();
    31.             onLoaderCallback = null
    32.         }
    33.     }
    34. }
     
    Last edited: Feb 8, 2021
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,138
    Looks like you're missing some semicolons to start, but you should always copy and paste your errors. They include crucial info. The semicolons are easy issues to fix and just get use to needing those. I highly advise that you learn how to use your IDE (whatever you are using to write your code) as it will point out these errors usually. And that should help you. Many times right clicking on an error and hitting the lightbulb (In Visual Studio at least) will show you possible fixes. :D

    Line 1 is missing a semicolon.
    Line 23 is missing semicolon
    Line 31 is missing a semicolon.
    Line 20 will also need a semicolon.
    Line 5 is incorrect. It should be UnityEngine.SceneManagement;
    Line 10 Is incorrect. Not sure what the 2.0 was for, but that isn't going to work in an enum.

    To add, if following a tutorial, helps to link it as well. While not everyone will go look at it, sometimes if they just show what the end script looks like, it's easy to reference.
     
    Last edited: Feb 8, 2021
  3. Mistycal

    Mistycal

    Joined:
    Feb 8, 2021
    Posts:
    6
    thanks man
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336