Making a league
Hello
Currently, I am creating a racing game. Right now, I am trying to make a league so that if you come first 1st in a race for example, you get 8 points, the next person gets 7, then 6, etc. etc.
However because Ive never done anything like this Im a bit unsure of what method I should use to create the league.
It isn't multiplayer, but should I have it so that you have to get a certain amount of points within a certain amount of matches to win (like Fifa Ultimate Team Seasons) or should I have a full-blown league, but make up who comes where in the race except for your player or should I try to somehow track the AI's finishes in the race (even though they're just instantiated prefabs.
Any advice would be welcome as Im really stuck here
Thanks
Dok
Answer by fafase · Aug 28, 2015 at 04:56 AM
Create a leaderboard class. It contains an array of PlayerRank. PlayerRank is a class containing the info you need for the leaderboard, name, points, car brand or others.
The array of your leaderboard is reordered at the end of a race. So when you finish, you grab the leaderboard and for each runner, you update the PlayerRank values. Then at the end, you reorder your array. The array is kept in PlayerPrefs so you can call it back next time you play. You would convert your PlayerRank to string, most likely overriding the ToString method and concatenate into a large string that you store with PlayerPrefs.SetString. When you run the game next game, you fetch that string and turn it back into PlayerRank values that you keep in RAM for the time of the game.
EDIT: I came up with a fully explained solution :
Answer by hislittlecuzin · Aug 27, 2015 at 12:35 PM
You can try declaring an empty "place" variable in each car, then fill that variable with a number for each place (first place is car 1, 2nd car 2...) then create a for loop or a really long if else script that assigns however many points to each car. (Idk how to code exactly but I understand concepts)
If player car place= 1st place { Then player car points = 8 }
I don't know exactly how to code it because I don't know all that much, nor do I know what your game objects are called, but I hope this helps.
@hislittlecuzin But how would I do this if I'm separately instantiating them
I assume make each car a public variable, or when the main game object part of the car passes the finish line, you can use that to deter$$anonymous$$e who crossed first, then add the points to the game object.
For the sake of proper program$$anonymous$$g, this is no good (at least to me). Your car should not know its position. Consider Lewis Hamilton's formula 1, the actual car, it does not have anything on it that makes it first on the ranking.
On the other hand, the ranking has a reference to Hamilton's car. And that is how you should think your program$$anonymous$$g design, as close to reality as possible. This is why I would recommend an independent leaderboard, that cars nor drivers have any clue of. This way, you can use your cars and drivers in races without championship ranking and this can be done without altering teh existing code that would contain leaderboard ranking.
@fafase I agree, it seems like a bit of an elaborate ruse and a scam to use this method.
Just feels like Im tricking the player
I apologize for not recommending a way that could work
Answer by Ashky · Aug 28, 2015 at 06:30 AM
I for one, would suggest having a trigger at the end of the race, with a script, that would assign 8 points to the first car that collides with it, then 7, and so on. If it's a circuit race, the same trigger can be used, but its behavior controlled by a variable that counts how many times a car has passed through and then assigns points.
You should create a script, let's call it CarDetails, that should contain a getter and setter for a _points variable, attach it to each car prefab, and in the trigger's OnTriggerEnter() or OnTriggerEnter2D(), depending on what you're using, call the collider's setter.
Your CarDetails script can also contain other things like names, car types, colors, whatever.
Afterwards, you can do whatever you want with the values, like storing them in your game manager singleton object, or in player prefs.
Look up triggers: http://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html and singletons:
http://unitypatterns.com/singletons/
EDIT: I think fafase's answer also works well.
Answer by AndrewBilotti · Jan 12, 2016 at 07:13 PM
Did you pass Algebra in school? Then make some functions!
Your answer
Follow this Question
Related Questions
Highscore with Dreamlo 3 Answers
How to get a for loop to run once per coroutine? 0 Answers
How can I check the destination outside the navmesh? 1 Answer
Help..... please..... how do I do this? 0 Answers