- Home /
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 1*2 = 2. So then you get 2 coins after level 1. If the level is 2, then it would be 2*2 = 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.
Answer by leebrond · Dec 21, 2017 at 04:26 AM
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;
Thanks it worked. I had to tweak it a little bit since my level select is build index 1. Here's what I did
level = Scene$$anonymous$$anager.GetActiveScene().buildIndex - 1;
reward = level * 2;
Your answer
Follow this Question
Related Questions
[SOLVED] First array slot blocking second array slot 1 Answer
Converting strings to numbers 1 Answer
Converting String to Integer is not working 1 Answer
Replace String Characters with certain Numbers 2 Answers
Floating Point and ToString issue 2 Answers