Trying to call scene.name from OnGUI

Hello everyone.

I am going through the old Unity Persistence Live Training, where they use Application.loadedLevel. I’m trying to use SceneManagement but the following code gives errors.

The problem is that I can’t call SceneManager from OnGUI(), but I can’t use GUI.Label in Start(). All the examples about using the IMGUI, use the old Application model. Unity - Manual: IMGUI Basics

Thank you,
Brian

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

public class ChangeScene : MonoBehaviour {

  void Start()
  {
  Scene scene = SceneManager.GetActiveScene();
  }
  void OnGUI()
  {
  GUI.Label(new Rect(10, 10, 100, 20), scene.name);
  }
}

I tinkered around and found the solution.

I’m not sure how to explain all my thought processes along the way. but the outcome is to just call the name directly from the SceneManager object.

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

public class ChangeScene : MonoBehaviour 
{  
  void OnGUI()
  {
  GUI.Label(new Rect(10, 10, 200, 20), "Current Scene: " + SceneManager.GetActiveScene().name);   
  }
}

-Brian