get scene name unity code example

Example 1: unity scene name get

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class GetSceneName : MonoBehavior {

	Scene m_Scene;
	string sceneName;

	private void Start() {
   		m_Scene = SceneManager.GetActiveScene();
   		sceneName = m_Scene.name;
 	}
}

Example 2: unity how to get the current scene

SceneManager.GetActiveScene().buildIndex;

Example 3: unity get scene name by index

private static string NameFromIndex(int BuildIndex)
 {
     string path = SceneUtility.GetScenePathByBuildIndex(BuildIndex);
     int slash = path.LastIndexOf('/');
     string name = path.Substring(slash + 1);
     int dot = name.LastIndexOf('.');
     return name.Substring(0, dot);
 }