Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Dok101 · Aug 27, 2015 at 10:18 AM · aileaderboardpoints

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

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 :

https://unitygem.wordpress.com/leaderboard-and-saving-data/

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dok101 · Aug 28, 2015 at 08:38 AM 0
Share

Thanks Im going to do this
This should work a charm

avatar image
1

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.

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dok101 · Aug 27, 2015 at 01:59 PM 0
Share

@hislittlecuzin But how would I do this if I'm separately instantiating them

avatar image hislittlecuzin · Aug 28, 2015 at 04:48 AM 0
Share

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.

avatar image fafase · Aug 28, 2015 at 06:29 PM 1
Share

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.

avatar image Dok101 · Aug 28, 2015 at 09:14 PM 0
Share

@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

avatar image hislittlecuzin · Aug 29, 2015 at 12:14 AM 0
Share

I apologize for not recommending a way that could work

Show more comments
avatar image
1

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by AndrewBilotti · Jan 12, 2016 at 07:13 PM

Did you pass Algebra in school? Then make some functions!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

30 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Highscore with Dreamlo 3 Answers

In AIThirdPersonCharacter, how to Stop Extraturn movement when character stops moving in Unity Standard Ai Third Person Controller Script? 0 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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges