using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class Coin : MonoBehaviour { // Use a static variable to track the coin count globally private static int CoinsCollected = 0; void OnTriggerEnter2D(Collider2D other) // Change to OnTriggerEnter2D for consistency with triggers { if (other.CompareTag("Player")) // Ensure the coin only reacts to the player { Destroy(gameObject); // Destroy the coin CoinsCollected++; // Increment the coin count // Check if the required coin count is met to load the next scene if (CoinsCollected == 3) { SceneManager.LoadScene("Level 2"); } else if (CoinsCollected == 6) { SceneManager.LoadScene("Level 3"); } else if (CoinsCollected == 9) { SceneManager.LoadScene("Level 4"); } else if (CoinsCollected == 12) { SceneManager.LoadScene("Level 5"); } else if (CoinsCollected == 17) { SceneManager.LoadScene("Level 6"); } else if (CoinsCollected == 22) { SceneManager.LoadScene("Level 7"); } else if (CoinsCollected == 25) { SceneManager.LoadScene("Level 8"); } else if (CoinsCollected == 28) { SceneManager.LoadScene("Level 9"); } else if (CoinsCollected == 31) { SceneManager.LoadScene("Level 10"); } else if (CoinsCollected == 34) { SceneManager.LoadScene("Win"); } } } }