on exiting scene unity code example Example: unity calling method before unloading scene SceneManager.sceneUnloaded += MyFunction;