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 Buretto · Dec 06, 2017 at 10:28 PM · bugplayerprefsif-statementsglitchtextmesh

If statement bug? (Glitch)

For some reason my if statement is not working as it should.

  private void Update()
    {
         i = Mathf.Round(transform.position.z + 14.96f);
         tm.text = i.ToString() + " m";
     }
 
     public void HighScore()
     {
         GameObject HighScoreObj = Instantiate(highScore);
         HighScoreObj.transform.position = new Vector3(transform.position.x + 4.4f,transform.position.y + 3.2f,transform.position.z - 0.12f);
         if (i > PlayerPrefs.GetFloat("HighScore"))
         {
             highScore.GetComponent<TextMeshPro>().SetText("New Record!");
             PlayerPrefs.SetFloat("HighScore", i);
             PlayerPrefs.Save();
         }
         if (i < PlayerPrefs.GetFloat("HighScore"))
         {
             highScore.GetComponent<TextMeshPro>().SetText("Record " + PlayerPrefs.GetFloat("HighScore") + "m");
         }
         Time.timeScale = 0;
     }

It is setting the text of what it should have been in the last playmode. For example, if i = 10 and PlayerPrefs.Float = 5 when HighScore() is called the text changes to "Record ". And if I enter another playmode test, it will make the text say "New Record!" even if i is less then the playerpref float. So summed up, it pretty much returns the if statement of the last playmode test. Is this a glitch with Unity or what? It is very frustrating because it is such basic code and yet I have not got it working, so any help would be very appreciated!

Comment
Add comment · Show 2
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 jchester07 · Dec 07, 2017 at 12:38 AM 0
Share

try

  if (i > PlayerPrefs.GetFloat("HighScore"))
  {
      highScore.GetComponent<Text$$anonymous$$eshPro>().SetText("New Record!");
      PlayerPrefs.SetFloat("HighScore", i);
      PlayerPrefs.Save();
  } else {
      highScore.GetComponent<Text$$anonymous$$eshPro>().SetText("Record " + PlayerPrefs.GetFloat("HighScore") + "m");
  }


Also check your playerprefs is saving properly. Get its value before entering your if statement.

avatar image Buretto jchester07 · Dec 07, 2017 at 03:03 AM 0
Share

That was actually my code to begin with, thanks for trying to help anyways. I think it is definitely a bug, I have parsed the float in my start function and it is definitely saving properly. I'll update this if I get it resolved!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Buretto · Dec 07, 2017 at 04:07 AM

OMG finally! It turns out it was an error with TextMeshPro. I had to convert to UGUI and it finally works!

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

78 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

Related Questions

Point of light bug 0 Answers

[Error] Error While Importing Packages 0 Answers

Variable changes to a negative number somehow 1 Answer

Assets Blinking on Game Play 0 Answers

Text MeshPro Input field insert integer? 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