From 88ed9dfb6bb54c6bec6edf3c4480b350226dbf93 Mon Sep 17 00:00:00 2001 From: Kaj Forney Date: Sun, 9 Oct 2022 23:13:24 -0600 Subject: [PATCH] Make all levels accessible. --- Assets/Scenes/level3.unity | 2 +- Assets/Scripts/Goal.cs | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Assets/Scenes/level3.unity b/Assets/Scenes/level3.unity index 1e478ba..32d372f 100644 --- a/Assets/Scenes/level3.unity +++ b/Assets/Scenes/level3.unity @@ -161411,7 +161411,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1955489873} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 17, z: 0} + m_LocalPosition: {x: 0, y: 13, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] diff --git a/Assets/Scripts/Goal.cs b/Assets/Scripts/Goal.cs index aefad6b..14f07fe 100644 --- a/Assets/Scripts/Goal.cs +++ b/Assets/Scripts/Goal.cs @@ -1,15 +1,37 @@ +using System; using UnityEngine; using UnityEngine.SceneManagement; public class Goal : MonoBehaviour { + private Scene currentScene; + private void Start() + { + currentScene = SceneManager.GetActiveScene(); + } + private void OnCollisionEnter2D(Collision2D other) { if (other.collider.CompareTag("Player")) { - Debug.Log("You win!!!"); GetComponent().Play(); - SceneManager.LoadScene("winScreen"); + nextLevel(); + } + } + + private void nextLevel() + { + switch (currentScene.name) + { + case "level1": + SceneManager.LoadScene("level2"); + break; + case "level2": + SceneManager.LoadScene("level3"); + break; + case "level3": + SceneManager.LoadScene("winScreen"); + break; } } }