gimm-platformer-project/Assets/Scripts/Goal.cs

38 lines
840 B
C#

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"))
{
GetComponent<AudioSource>().Play();
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;
}
}
}