1

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?

1 Answer 1

2

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.