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 /
avatar image
0
Question by zak666 · Oct 17, 2017 at 03:46 AM · listintget

Get score from list?

hey gang trying to display scores from my list, should be a simple thing haven't been able to get it to work was wondering how i can get it. however its not displaying anything in my text. :(

should be something like FistPlace.text = scoresList[0].ToString();

 public class ScoreTRacker : Photon.MonoBehaviour {
     public List<int> scoresList;
 
         public int Player1Score = 1000;
     public int Player2Score= 4000;
     public int Player3Score= 2000;
     public int Player4Score= 3000;
 
 public Text FistPlace;
     public Text SecondPlace;
     public Text FourthPlace;
     public Text ThirdPlace;
 
 
 void EndGame(){
 scores.Add(Player1Score);
         scoresList.Add(Player2Score);
         scoresList.Add(Player3Score);
         scoresList.Add(Player4Score);
         scoresList.sort();    // put in order
 
 }
 
 
 
 void Update(){
 
 
         int one = 0;
         int two = 1;
         int three = 2;
         int four = 3;
 
 
 // display in order from  first in list to last....

 FistPlace.text = scoresList[one].ToString();
 SecondPlace.text = scoresList[two].ToString();
 ThirdPlace.text = scoresList[three.ToString();
 FourthPlace.text = scoresList[four].ToString();
 
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by unit_nick · Oct 17, 2017 at 04:34 AM

I realize it's not exactly what you have asked for but thought I would show custom list sorting in case it's useful

     public List<Player> players;
 
     public class Player
     {
         public int id
         {
             get { return _id; }
         }
 
         public int score
         {
             get { return _score; }
             set { _score = value; }
         }
 
         private int _id;
         private int _score;
 
         public Player(int id)
         {
             _id = id;
             _score = 0;
         }
     }
 
     private void Start()
     {
         players = new List<Player>();
         for (int i = 0; i < 4; i++) players.Add(new Player(i));
 
         players[0].score = 3;
         players[1].score = 2;
         players[2].score = 8;
         players[3].score = 1;
     }
 
     private void Update()
     {
         players.Sort(delegate (Player a, Player b)
         {
             if (a.score > b.score) return -1;
             else return 1;
         });
 
         foreach(Player player in players)
         {
             Debug.Log(String.Format("Player {0} score = {1}", player.id, player.score));
         }
     }
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

72 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 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 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

A node in a childnode? 1 Answer

Comparing int from list1 to int from list2 0 Answers

I want some ints stored in a new int right after eachother 1 Answer

using char to extract integer numbers from a list - [UnityScript] 1 Answer

Can I create a list with an int/float and a string? C# 2 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