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 batopaa · May 27, 2015 at 10:59 AM · javascriptplayerprefsscore systemhighscoregui.box

Im Doing HighScore System To My Game And There Is Something Wrong In My Scripts

So Im Doing highScore System When Players Health Is 0 It Sets New highscore But There Is Problem That When Helath Is 0 Nothing Happens

-------HealthScript--------

 var curHealth : int = 100;
  function Start(){
  }
  
 function OnGUI(){
 GUI.Box(Rect(Screen.width*0.9,Screen.height*0.5,100,25), curHealth.ToString());
 }
  
 function OnTriggerEnter (other : Collider) {
  
       if(other.gameObject.tag == "enemy")
       curHealth -= 10; 
  }




-------ScoreScript--------

 #pragma strict
 
  var highScore: int = PlayerPrefs.GetInt("HighScore");
 
 function Start(){
  InvokeRepeating("EachSecond",1.0,1.0);
  }
 
  var Elkit : GameObject;
  var score: int = 0;
  var addscore = 7;
 var HighScore : int;
  function EachSecond()
  {
  score=score+addscore;
  }
  function OnGUI(){
  GUI.Box(Rect(Screen.width*0.9,Screen.height*0.2,100,25), score.ToString());
  var health : Health;
 health = Elkit.GetComponent("Health");
 
 if(health.curHealth == 0 && score <= highScore)
 {
 PlayerPrefs.SetInt("HighScore",score);
 
 
 } 
  }


---------HighScoreScript-----------

 #pragma strict
 var highScore: int = PlayerPrefs.GetInt("HighScore");
 function Start () {
 
 
 }
 function OnGUI(){
  GUI.Box(Rect(Screen.width*0.9,Screen.height*0.3,100,25), highScore.ToString());
     }

Comment
Add comment · Show 3
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 Ekta-Mehta-D · May 27, 2015 at 11:20 AM 1
Share

Add that condition in Update() and for checking new score as highscore you will have condition like score > highscore then score value will be set as a new high score.

Thanks.

avatar image SterlingSoftworks · May 27, 2015 at 04:19 PM 1
Share

Also, with your HighScoreScript you are only "getting" the high score value one time. If you put a PlayerPrefs.GetInt("HighScore"); in the OnGUI() function before the GUI.Box it should update properly as well.

avatar image batopaa · May 27, 2015 at 05:53 PM 0
Share

Thanks! Now Its Working!

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

using playerprefs to update a guitext and record highscores 1 Answer

Setting, saving and getting info from PlayerPrefs, i can't save and call a highscore 1 Answer

How to add playerPrefs to this script? 1 Answer

Highscore won't save 3 Answers

How do you run multiple Playerprefs scripts (JS)? 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