Avoid using strings in LoadScene

Hi.
Just wanted to share something i managed to find out.

I also dislike to hard code ints or strings in functions. You will forget at least one important, and changes will cause …strangeness. Just as Rick said.

And if there’s a will there’s a way. Now this of course only works if you have your Game Over scene as the absolute last one.

private void OnTriggerEnter2D(Collider2D collision)
{
	SceneManager.LoadScene(SceneManager.sceneCountInBuildSettings - 1);
}

All the best
G

1 Like

Privacy & Terms