I want to acquire scene name to apply it in a condition.

I have an int variable 'audioplay' that is going to determine which AudioClip to play.

I tried

if (Scene == "main") {
    audioplay = Random.Range (1, 3);
} else if (Scene == "menu") {
    audioplay = 3;

But I get the error "error CS0118: 'UnityEngine.SceneManagement.Scene' is a 'type' but a 'variable' was expected".


The SceneManagement namespace gives access to the active scene:

using UnityEngine.SceneManagement;

var currentScene = SceneManager.GetActiveScene();
var currentSceneName = currentScene.name;

In your code, I'm assuming that Scene has been returned from GetActiveScene, so you just need to change it to Scene.name.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.