Home > database >  I'm having an error in unity for a script that changes the scene to another scene
I'm having an error in unity for a script that changes the scene to another scene

Time:12-03

This is an image of the errors This is the script

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

public class LevelComplete : MonoBehaviour
{
    public void LoadNextLevel ()
    {
        SceneManager.LoadScene(SceneManager.GetActiveScene().BuildIndex   1);
    }
}

Please help me with the errors

I tried to debug the error by checking the script and UI animations that connect to the event that changes the scene. I also tried using SceneManager.LoadScene (name); but it did not work.

CodePudding user response:

You have two issues here. First of all, you declared the class twice. It might be twice in the same file, or in different files. Second of all, you need to use UnityEngine.SceneManagement instead of SceneManager.

The simplest solution is to check for double declarations, and for the using, replace using UnityEngine.SceneManager; with using UnityEngine.SceneManagement.

  • Related