using UnityEngine; using UnityEngine.SceneManagement; public class Finish : MonoBehaviour { [SerializeField] private GameObject finishScreen; // UI element to display the game finish message [SerializeField] private string nextScene = "MainMenu"; // The name of the next scene to load private bool gameFinished = false; private void OnTriggerEnter2D(Collider2D collision) { if (collision.CompareTag("Player") && !gameFinished) { FinishGame(); } } private void FinishGame() { gameFinished = true; finishScreen.SetActive(true); // Display the finish screen Time.timeScale = 0f; // Pause the game } public void OnFinishButtonPressed() { Time.timeScale = 1f; // Resume the game SceneManager.LoadScene(nextScene); // Load the next scene } }