Im making a level where when the player collides with a sprite with a box collider, the next scene loads. For whatever reason, the scene just won't load but it also wont error out either. I have both colliders set to trigger, the player has a rigidbody, I made sure to put the next level scene name into the string reference box provided on the gameobject's script, nothing shows up on the console, and both scenes are in build settings. If anyone has an idea of what is going on, your help is much appreciated. Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class SceneMan : MonoBehaviour { [SerializeField] private string newLevel; void OnTriggerEnter2d(Collider2D other) { if (other.CompareTag("Collider")) { SceneManager.LoadScene(newLevel); } } }
Spelling and capitalization are both critical in programming. This is the reference for the function you think you are implementing: https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnTriggerEnter2D.html Note the capitalization of the final letter in the function name and compare it to your code.
[SerializeField] private string newLevel; needs to be cast as an integer. Also make sure the integer represents a Build Setting index number of the correct scene wanting to load.
I'm going to guess he's intentionally using the string overload version of LoadScene: https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadScene.html That overload takes a string and it is the name, not the sequential number. Usually that is good enough and easier to debug, and lets you reorder the scenes trivially.
Before you call the "SceneManager.LoadScene("GameScene"), make sure you added the scene itself to the "buildSettings" to your project. Otherwise both the called by name and index won't work. Hope it solves the problem of yours
You need use OnTriggerEnter2D(Collider2D other) method, but you use OnTriggerEnter2d(Collider2D other) method. You need big D at the end letter not small