Unity Scene 获取当前场景的名称

获取当前场景的名称

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

public class Test001 : MonoBehaviour {
    void OnGUI(){
        Scene scene = SceneManager.GetActiveScene ();
        GUILayout.Label ("当前场景: " + scene.name);
    }
}

假如当前场景创建后还没有保存则不会显示出名字。

旧写法:

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

public class Test001 : MonoBehaviour {

    void OnGUI(){
        GUILayout.Label ("当前场景: " + Application.loadedLevelName);
    }
}

你可能感兴趣的:(Unity Scene 获取当前场景的名称)