Nobert
Nobert

Reputation: 163

Unity namespace error does not exist with SceneManager

I am using unity SceneManager but it gives me a namespace error that it does not exist in

using UnityEngine;
using UnityEngine.SceneManagement;

public class ManageGame : MonoBehaviour
{

    bool gameHasEnded = false;

    public void GameOver()
    {
        if (gameHasEnded == false)
        {
            gameHasEnded = true;
            Debug.Log("GAME OVER");
            Restart();
        }

    }

    void Restart () 
    {
        SceneManagement.LoadSceneMode(SceneManager.GetActiveScene().name);
    }


}

I read the official documentation about SceneManger and i checked the using part and it was the same. My version is 2019.3.14. Why does this happen?

Upvotes: 1

Views: 4307

Answers (1)

julienkay
julienkay

Reputation: 61

Could you post some more information about your script? Which method of SceneManager are you trying to call and how exactly does this code look like? What's your Unity version? What are your other 'using' statements?

Without having more details we can only guess: Both the 'UnityEditor' as well as the 'UnityEngine' namespace contain a SceneManagement namespace, which might be causing some confusion.

EDIT: Thanks for updating the question with more information. I see two issues:

1.) You are trying to call a method on a namespace (SceneManagement is a namespace not a class). Instead you want to access the class SceneManager in the SceneManagement namespace.

2.) LoadSceneMode() is not a method in SceneManager. There's an enum with that name, but no method. You want to use the method LoadScene()

So the correct line would be:

SceneManager.LoadScene(SceneManager.GetActiveScene().name);

Upvotes: 2

Related Questions