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 CodewithFin · Apr 13, 2016 at 05:21 PM · c#unity 5highscores

error CS0201?

I'm making a highscore box in the main menu. In the script I have, i've gotten it down to one error on this line:

hscorecount == PlayerPrefs.GetInt(highScoreKey, 0);

The error: CS0201: 'Only assignment, call, increment, decrement, and new object expressions can be used as a statement'.

All the code:

 void Start()
 {
     //Get the highScore from player prefs if it is there, 0 otherwise.
     hscorecount == PlayerPrefs.GetInt(highScoreKey, 0);
 }

 void Update()
 {
     GetComponent<GUIText>().text = "Score: " + score.ToString();
 }

 void OnDisable(){
      
      //If our scoree is greter than highscore, set new higscore and save.
      //for (i = 0; i<hscorecount.Length; i++){
          
          //Get the highScore from 1 - 5
         // highScoreKey = "HighScore"+(i+1).ToString();
          //hscorecount = PlayerPrefs.GetInt(highScoreKey,0);
          
          //if score is greater, store previous highScore
          //Set new highScore
          //set score to previous highScore, and try again
          //Once score is greater, it will always be for the
          //remaining list, so the top 5 will always be updated
  
          if(score > hscorecount){
              int temp = hscorecount;
              PlayerPrefs.SetInt(highScoreKey,score);
                  score = temp;
          }
      }
  }

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 Rob2309 · Apr 13, 2016 at 05:59 PM

A double equal sign compares the two values, which is invalid in that context, what you want to do is only use a single one, which assigns the value to the specified variable... In the code you posted, however, this error is already fixed so i guess you have already found the solution :D

Comment
Add comment · Show 3 · 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 CodewithFin · Apr 13, 2016 at 06:05 PM 0
Share

If I make it just one equals sign, the error: Cannot implicitly convert type 'int' to 'int[]' ..?

avatar image Rob2309 CodewithFin · Apr 13, 2016 at 06:08 PM 0
Share

is your hscorecount an array?

avatar image CodewithFin · Apr 13, 2016 at 06:15 PM 0
Share

I'm new to c# so i'm not completely sure what an array is, I have 'hscorecount' as a static float in a 'HUD script', the 'HUD script' saves the highest score to player prefs and displays it on the screen while playing, but what i'm trying to do is display the top five scores on the main menu.

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

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

Guys i Need Guidance with high score C# 1 Answer

how to implement online leader board to my project? 0 Answers

Displaying Local High Scores. 0 Answers

Photon Networking - How to move all players from game scene to current room scene? 0 Answers

How to call a function every second ? 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