Checking current scene name using SceneManager

前端 未结 1 676
谎友^
谎友^ 2020-12-12 07:22

So I\'ve decided to split my game into separate scenes(main menu, gameover, etc.) And I\'m trying to use an if statement in my code to check if the current scene is \"gameov

相关标签:
1条回答
  • 2020-12-12 08:15

    You're getting an error here because SceneManager.GetActiveScene() returns an object of type SceneManager.Scene, not a string. However, according to the documentation, this gives you access to the public Scene.name, which is a string.

    So the non-deprecated equivalent of:

    if (Application.loadedLevelName == "gameover") {
        // ...
    }
    

    Would be:

    if (SceneManager.GetActiveScene().name == "gameover") {
        // ...
    }
    
    0 讨论(0)
提交回复
热议问题