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 /
This question was closed Aug 04, 2014 at 10:04 AM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Kreativity · Aug 03, 2014 at 11:57 PM · error

Game Over page score is always 0

I'm following Mike Geig's infinite runner tutorial but even though the scripts are identical my game over page always says 0 as the score and I don't know why.

this is the game over script where I think something might be wrong

 using UnityEngine;
 using System.Collections;
 
 public class GameOverScript : MonoBehaviour {
     
     int score = 0;
 
     void Start () {
         score = PlayerPrefs.GetInt("score");
     }
 
     void OnGUI()
     {
         GUI.Label(new Rect (Screen.width / 2 - 40, 50, 80 ,30), "Game Over");
 
         GUI.Label(new Rect (Screen.width / 2 - 40, 300, 80, 30), "Score: " + score);
         if(GUI.Button(new Rect (Screen.width / 2 - 30, 350, 60, 30), "Retry?"))
         {
             Application.LoadLevel (0);
         }
     }
 
 }
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 meat5000 ♦ · Aug 03, 2014 at 11:55 PM 2
Share

You've got

 PlayerPrefs.GetInt("score");

But do you ever Set it?

avatar image Kreativity · Aug 04, 2014 at 12:42 AM 0
Share

yes right here line 19

 using UnityEngine;
 using System.Collections;
 
 public class HUDScript : $$anonymous$$onoBehaviour {
 
     float playerScore = 0;
 
     void Update () {
         playerScore += Time.deltaTime;    
     }
 
     public void IncreasedScore(int amount)
     {
         playerScore += amount;
     }
 
     void OnDisable()
     {
         PlayerPrefs.SetInt("Score", (int)playerScore * 100);
     }
 
     void OnGUI()
     {
         GUI.Label(new Rect(10, 10, 100, 30), "Score: " + (int) (playerScore * 100));
     }
 }
 



avatar image Kreativity · Aug 04, 2014 at 12:43 AM 0
Share

oh wait I figured it out, I had the get as a capital S but the set was a lowercase

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by Kiwasi · Aug 04, 2014 at 12:44 AM

You are getting "score" and setting "Score". Strings are case sensitive, so these two variables are different.

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

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Error in script I haven't even opened 0 Answers

Unity Script Editor Not Working 1 Answer

Crash on .exe but fine on editor... 1 Answer

Error with code, cannot figure out solution... 1 Answer

What's wrong with this script? 2 Answers


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