I am trying to make a simple game where the player jumps and collects animated coins. After collecting all the coins, the scene is supposed to change. For some reason, my character collects the coins but the scene doesn't change.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class Coins : MonoBehaviour { [SerializeField] private string newLevel; public int coinAmount; int coins ; void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("Player")) { coins += 1; Destroy(gameObject); addCoins(); } } void addCoins() { coins++; if (coins == coinAmount) { SceneManager.LoadScene(newLevel); } } } 