- Home /
different score amounts for each level
hi all, im creating a golf type game which uses a par system, giving stars out at the end of a level depending how many shots the players takes to complete it. like angry birds, the least number of shots gives 3 stars.
my problem lies with the score system, each level will have a different set of par scores, for examaple level 1 will give 3 stars at 2 shots or less, where level 2 gives 3 stars on 4 shots or less.
so far i figured id create a bunch of floats in another "master score script" eg: level1_parcount_1star = 1 level1_parcount_1star = 3 level1_parcount_1star = 6 and so on for each level.
my 1st problem is how would i call in another script back to these to check these values. i dont want to make a differnet scri[pt for each level, i need a way to;
call the master score script, find current level find par count for current level
so far im messing around with this kind of line, this would use the current levels name ParBerry3 = uiScoreBack.GetComponent().((application.loadedlevelname)Par3Count)
any help would be great =]
Answer by Kurius · Nov 13, 2013 at 08:21 PM
You should store all of that data in Unity PlayerPrefs. see here
i thought about using playerprefs, but would i make a call at the start of the game giving all the levels there score counters?
At the beginning of the game, perform a read of the PlayerPrefs. If PlayerPrefs is read to be empty, then at this time set the default values, else read the current values and display them. At the end of each level that the user plays, update the PlayerPrefs with the latest values. Next time the user plays the game, the PlayerPrefs will have remembered what the latest values were.
Answer by Entwicklerpages · Nov 13, 2013 at 09:32 PM
I think it would be a good idea to make a simple MonoBehaivor that has only some public vars. (for example integers) You put the Script Component with this Behaivor on something like a "LevelController" object. Then you set the least number for this level.
You can get these integers simply with something like this (C#)
YourDataClass data = levelController.GetComponent<YourDataClass>();
Debug.Log(data.leastShots);
Please don't make a gigantic class with tons of vars in it! Each time you add a level you must edit this class and put a bunch of new vars in it. Simple make one MonoBehavior class and put that Component in the levels. Then you can simply edit your settings in the editor.