public void PassBarrier() { ElevatorBarrier barrier = barriers.First.Value; GameObject.Destroy(barrier.gameObject); barriers.RemoveFirst(); LoadNextScene(); ++currentSceneIndex; }
private void OnSceneLoaded(Scene scene, LoadSceneMode mode) { Debug.Log("Loaded " + scene.name); Vector3 scenePosition = Vector3.zero + startPoition; if (reloadingScene) { Debug.Log("Reloaded " + scene.name); scenePosition = GetCurrentScenePosition(); } else if (scenePositions.Count > 0) { scenePosition = scenePositions.Last.Value + new Vector3(0, sceneSpacing, 0); } GameObject[] rootObjects = scene.GetRootGameObjects(); foreach (GameObject rootObject in rootObjects) { rootObject.transform.position += scenePosition; Light[] lights = rootObject.GetComponentsInChildren <Light>(); foreach (Light light in lights) { if (light.type == LightType.Directional) { light.enabled = false; } } NVRPlayer player = rootObject.GetComponentInChildren <NVRPlayer>(); if (player != null) { GameObject.Destroy(player.gameObject); } RobotHoppy[] hoppies = rootObject.GetComponentsInChildren <RobotHoppy>(); foreach (RobotHoppy hoppy in hoppies) { hoppy.IgnoreCollision = false; } } //when restarting a scene, we don't want to recreate the barrier or add anything back into the lists if (reloadingScene) { LinkedListNode <Scene> sceneNode = scenes.First; for (int i = 0; i < currentSceneIndex; ++i) { sceneNode = sceneNode.Next; } Debug.Log("Replacing " + sceneNode.Value.name + " in list"); sceneNode.Value = scene; return; } if (nextSceneIndex < sceneNames.Length) { GameObject barrierObject = GameObject.Instantiate(barrierPrefab); ElevatorBarrier barrier = barrierObject.GetComponent <ElevatorBarrier>(); barrier.transform.position += scenePosition; barrier.ElevatorObj = this; barrier.PlayerHead = playerHead; barriers.AddLast(barrier); } else { endPosition = barriers.Last.Value.transform.position; } scenePositions.AddLast(scenePosition); scenes.AddLast(scene); if (scenes.Count > SceneLoadedCount) { UnloadScene(); } }