void OnTriggerExit(Collider collider) { if (!_exitPortalSceneLoader || !_exitPortalSceneLoader._inTrigger) { Debug.Log("Unloading scene: " + _exitScene); SceneManager.UnloadSceneAsync(_exitScene); _exitPortalSceneLoader = null; } _inTrigger = false; }
void Awake() { _inTrigger = false; _exitPortalSceneLoader = null; _portal = GetComponentInParent <Portal>(); if (!_portal) { Debug.LogErrorFormat("Must have {0} script attached to parent GameObject", typeof(Portal).Name); return; } }
void OnSceneLoaded(Scene scene, LoadSceneMode mode) { // TODO: Fix compare if (string.Compare(scene.name, _exitScene.name, true) != 0) { return; } // TODO: Seems like there is a bug in unity causing scene.isLoaded to be false during OnSceneLoaded. // Will need to work around that. //GameObject exitPortalObj = FindObjectInScene(scene, _exitPortalName); GameObject exitPortalObj = GameObject.Find(_exitPortalName); if (!exitPortalObj) { Debug.LogErrorFormat("Could not find portal GameObject \"{0}\" in scene \"{1}\"", _exitPortalName, _exitScene.name); return; } Portal exitPortal = exitPortalObj.GetComponent <Portal>(); if (!exitPortal) { Debug.LogErrorFormat("Found object \"{0}\" in scene \"{1}\", but it does not have a {2} script attached", _exitPortalName, _exitScene.name, typeof(Portal).Name); return; } PortalAsyncSceneLoader exitPortalSceneLoader = exitPortalObj.GetComponentInChildren <PortalAsyncSceneLoader>(); if (!exitPortalSceneLoader) { Debug.LogErrorFormat("Found object \"{0}\" in scene \"{1}\", but it does not have a {2} script attached", _exitPortalName, _exitScene.name, typeof(PortalAsyncSceneLoader).Name); return; } _portal.ExitPortal = exitPortal; exitPortal.ExitPortal = _portal; _exitPortalSceneLoader = exitPortalSceneLoader; exitPortalSceneLoader._exitPortalSceneLoader = this; // Workaround for a bug where RenderSettings.reflectionIntensity gets set to 0 on scene load. // Potentially related: https://issuetracker.unity3d.com/issues/changing-reflection-intensity-at-runtime-via-script-doesnt-work float savedReflectionIntensity = RenderSettings.reflectionIntensity; RenderSettings.reflectionIntensity = -1.0f; RenderSettings.reflectionIntensity = savedReflectionIntensity; }