I’m trying to make a really simple script (because I’m still new to scripting) so when my 2D character enters the collider the next level will start. I’ve been literally working on this one script for 30-40minutes. I just need the script to work and for me to be able to edit the numbers in the editor so they can be used on each level and I don’t have to remake the script.
Script here:
function onTriggerEnter2D(other: Collider2D) {
SceneManagement.SceneManager.LoadScene(“”);
}
Once again, not good at scripting but I’m really trying here, any help would be great.
You can easily do what your asking by ensuring that all scenes are in the build order and by extending your script just a little bit.
//This is the value you assign in the inspector.
public int mySceneToLoad;
function onTriggerEnter2D(other: Collider2D)
{
SceneManagement.SceneManager.LoadScene(mySceneToLoad);
}
This should work and give you a public variable in the editor:
var levelToLoad : int;
function OnTriggerEnter2D(other : Collider2D){
SceneManagement.SceneManager.LoadScene(levelToLoad);
}
or a string instead of an int if you want to use names.
The reason it’s not working is also because of the function name not starting with a capital O. To check if something is running at all I always like to do a quick Debug.Log(“nameOfFunction”) when I try to figure out where the problem lies.