Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Kaltic · Dec 05, 2011 at 09:08 AM · textnametextfieldhighscorehigh

HighScore Names

This is currently my script for a local high score system in my game. Everything works, but the inputting the names. What I want is for once you get to the screen with the high scores, you will be prompted to enter your initials (if you do get a high score). It then stores the initials with the correct score (which are two separate arrays). I'm just not sure how to get the string from the textfield that you enter to be paired with the score.

 var position : int;        // position to enter new hgih score
 var positionName : int;        // position where to enter name
 var switched : boolean = false;        // whether or not a score has been replaced
 
 var HighS1 : GUIText;
 var HighS2 : GUIText;
 var HighS3 : GUIText;
 
 var Name1 : GUIText;
 var Name2 : GUIText;
 var Name3 : GUIText;
 
 var entName : String = "";
 
 function OnGUI () {
 entName = GUI.TextField (Rect (Screen.width/2 - 25, Screen.height/2 + 125, 50, 20), entName, 3);
 }
 
 function Start(){    
     HighScore();
 }
 
 function HighScore(){
     for(position = 0; position < GlobalStats.High.length; position++){
         if(switched == false && (GlobalStats.TotalScore > GlobalStats.High[position])){        // replace with new score
             positionName = position;
             switched = true;
             for(curPos = GlobalStats.High.length - 1; curPos > 0;curPos--){    // shift scores to the right
                 GlobalStats.High[curPos] = GlobalStats.High[curPos - 1];
             }
             GlobalStats.High[position] = GlobalStats.TotalScore;
         }
     }
     
     GlobalStats.HighName[positionName] = entName;
     
     HighS1.text = GlobalStats.High[0].ToString();
     HighS2.text = GlobalStats.High[1].ToString();
     HighS3.text = GlobalStats.High[2].ToString();
     
     Name1.text = GlobalStats.HighName[0].ToString();
     Name2.text = GlobalStats.HighName[1].ToString();
     Name3.text = GlobalStats.HighName[2].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 Statement · Dec 05, 2011 at 10:45 AM

Maybe you could just use positionName and change the value each OnGUI? If your backing end storage is PlayerPrefs, then you probably should use another variable that guards writing to PlayerPrefs only when the user is done editing the name...

Oh and you probably need to reorganize the name array when you reorganize the score array..

 var position : int;     // position to enter new hgih score
 var positionName : int;     // position where to enter name
 var switched : boolean = false;     // whether or not a score has been replaced
 
 var HighS1 : GUIText;
 var HighS2 : GUIText;
 var HighS3 : GUIText;
 
 var Name1 : GUIText;
 var Name2 : GUIText;
 var Name3 : GUIText;
 
 var entName : String = "";
 
 function OnGUI () {
   entName = GUI.TextField (Rect (Screen.width/2 - 25, Screen.height/2 + 125, 50, 20), entName, 3);
 
   // ******************************************
   // Just change the name directly, if feasible
   // ******************************************
   GlobalStats.HighName[positionName] = entName;
 }
 
 function Start(){   
     HighScore();
 }
 
 function HighScore(){
     for(position = 0; position < GlobalStats.High.length; position++){
        if(switched == false && (GlobalStats.TotalScore > GlobalStats.High[position])){     // replace with new score
          positionName = position;
          switched = true;
          for(curPos = GlobalStats.High.length - 1; curPos > 0;curPos--){    // shift scores to the right
           GlobalStats.High[curPos] = GlobalStats.High[curPos - 1];
 
           // ***********************************************
           // We probably need to reorganize the names aswell?
           // ***********************************************
           GlobalStats.HighName[curPos] = GlobalStats.HighName[curPos - 1];
     
          }
          GlobalStats.High[position] = GlobalStats.TotalScore;
        }
     }
 
     GlobalStats.HighName[positionName] = entName;
 
     HighS1.text = GlobalStats.High[0].ToString();
     HighS2.text = GlobalStats.High[1].ToString();
     HighS3.text = GlobalStats.High[2].ToString();
 
     Name1.text = GlobalStats.HighName[0].ToString();
     Name2.text = GlobalStats.HighName[1].ToString();
     Name3.text = GlobalStats.HighName[2].ToString();
 }
Comment
Add comment · Show 2 · 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 Kaltic · Dec 05, 2011 at 09:21 PM 0
Share

The problem is that the name won't show up until I replay the game. At the screen for highscores, when I enter a name, it doesn't show that it replaces the text in HighName[] until I come back to the high score scene again.

I know that I could fix this by getting the player to enter their name at the beginning of the game, but I really want them to enter their name when they reach the highscore scene.

avatar image Kaltic · Dec 05, 2011 at 09:38 PM 0
Share

Also it is not only replacing the correct HighName[] but then also takes the place of the next HighName[] when you play the next time. $$anonymous$$eaning if you play and enter HHH as your name it then stores it to the associated score, but then the next time you get to the highscore scene (and you got another highscore) then it will show that name is already being there.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

how to put the name of a car ??? 0 Answers

How to changes font, color & size of the text in textfield? 2 Answers

Textfield doubt, multiplayer purpose... 2 Answers

TextField text component not updating 2 Answers

Text field in Flash not recognize CTRL 1 Answer


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