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 Trojan1980 · Mar 25, 2014 at 08:51 AM · game save

Using Playerprefs???

Ok. I know i'm meant to use playerprefs but i keep getting errors i want to save my high score so it displays on the main menu when you return to it and every tome you load the game up how would i do this?

The attached is what ive got that gets the score every time i go through the checkpoint any help would be really appreciated :) Thanks. alt text

capture.png (18.5 kB)
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 getyour411 · Mar 26, 2014 at 10:34 PM 0
Share

Please do not post code as an image, post code as simple code and use the 10101 button to highlight it.

avatar image Trojan1980 · Mar 27, 2014 at 06:51 AM 0
Share

Sorry about that never posted on here before so here's the code again :)

 var prefabExplode: Transform;
 var prefabGameOver: Transform;
 
 function OnTriggerEnter( collision : Collider )
 {
     if(collision.gameObject.tag  == "walls")
     
 {
             var prefabExplode = Instantiate(prefabExplode, gameObject.transform.position, transform.rotation);
             var prefabGameOver = Instantiate(prefabGameOver, gameObject.transform.position, transform.rotation);
             
 
     Destroy(gameObject);
 
 }
 if(PlayerPrefs.Has$$anonymous$$ey("score")){
     myScore = PlayerPrefs.GetInt("score");
 }else{
     myScore = 0;
 }
 
 if(PlayerPrefs.Has$$anonymous$$ey("score")){
     PlayerPrefs.SetInt("score", $$anonymous$$athf.$$anonymous$$ax(myScore, PlayerPrefs.GetInt("score")));
 }else{
     PlayerPrefs.SetInt("score", myScore);
 }
 {
 
 CheckPoint.Score +=1;
 
 z_axis_forward.ZAxisSpeed +=0.003;
 
 
         }
 
 }
 
      

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by wijesijp · Mar 25, 2014 at 09:00 AM

Your problem maybe line 15 Destroy(gameObject)

If you want to destroy other object you have to use Destroy(collision.gameObject)

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
avatar image
0

Answer by JuanGomez · Mar 25, 2014 at 09:10 AM

This is when reading:

 if(PlayerPrefs.HasKey("score")){
     myScore = PlayerPrefs.GetInt("score");
 }else{
     myScore = 0;
 }

This is for writing:

 if(PlayerPrefs.HasKey("score")){
     PlayerPrefs.SetInt("score", Mathf.Max(myScore, PlayerPrefs.GetInt("score"));
 }else{
     PlayerPrefs.SetInt("score", myScore);
 }

Good luck :)

Comment
Add comment · Show 1 · 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 Trojan1980 · Mar 26, 2014 at 10:33 PM 0
Share

Thanks for that response i had to tweak it just a little so i didn't get any errors :)

but i'm still not sure if i'm doing this right or not, do i need to add this script to a game object or something? so that i can get the high score to save on the main menu as at the moment it doesn't seem to be doing anything yet?

I use to use game maker 8 so this is a big step for me...lol

Thanks again. alt text

capture.png (28.8 kB)
avatar image
0

Answer by Fappp · Mar 25, 2014 at 09:22 AM

Try changing this line:

 if(collision.gameObject.tag == "walls";

With this one:

 if (collision.CompareTag ("walls")) {

If you get an error add gameObject to it:

 if (collision.gameObject.CompareTag ("walls")) {

Please let met know if this fixed your issue!

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
avatar image
0

Answer by corriedotdev · Mar 25, 2014 at 09:26 AM

You have on trigger enter? You not want OnCollisionEnter? Especially if your object is tagged.

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

24 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

Related Questions

UnitySerializer Only Saving one Game Problem 0 Answers

Save Transform in PlayerPrefs 2 Answers

Mass Saving/Loading 0 Answers

Game Inside Game 0 Answers

How do you enable saving on android? 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