Figure out what level it is from Scene Name.

I want to make the player get rewarded after beating each level, but I want to make it so that beating higher levels will give you more rewards. Let’s say the scene is called “Level1”, so the level is level 1. The code would do 12 = 2. So then you get 2 coins after level 1. If the level is 2, then it would be 22 = 4. However, I can’t figure out how to get the GameManager to know what level it’s in. I don’t want to individually enter what level it is to the GameManager. I want to make it automatically know what level it is using the Scene name.

You can get it by setting your level1 to buildindex 1. and then in the script you can make like this :

int level = SceneManager.GetActiveScene().buildIndex;

int reward = level * 2;