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 SUPPEAR · Apr 03, 2015 at 07:48 PM · android2dscore

Displaying the score after a reset.

Hello. I am working on a game that is for the Android and is 2D. I am having a problem with displaying score. The script I use involves a Void Awake that is set to reset the score ( Which is what I want. ) When the game is finished it takes you to a different scene that is the menu. I want the latest score to be displayed on that menu instead of just resetting it to zero. I am using this script for the Score

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class ScoreManager : MonoBehaviour
 {
     public static int score;        // The player's score.
     
     
     Text text;                      // Reference to the Text component.
     
     
     void Awake ()
     {
         // Set up the reference.
         text = GetComponent <Text> ();
 
         score = 0;
         
     }
     
     
     void Update ()
     {
         // Set the displayed text to be the word "Score" followed by the score value.
         text.text = "Score: " + score;
     }
 }


The score is updated by each click on a gameObject in the game, if useful I will put that script on to. I have made a different post where I just removed the Awake function, but resetting the score seems impossible. The name of the UIText where the score is displayed is called ScoreText. All help is very appreciated.

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 UNZoOM · Apr 03, 2015 at 07:55 PM 0
Share

you need to put that script or atlesat the code snippet where and how you update score.

avatar image SUPPEAR · Apr 03, 2015 at 08:10 PM 0
Share

This is the Script that updates the score.

 using UnityEngine;
 using System.Collections;
 
 public class Score : $$anonymous$$onoBehaviour {
     
     public int scoreValue = 1;
     // Update is called once per frame
     void On$$anonymous$$ouseDown () {
     
         Score$$anonymous$$anager.score += scoreValue;
 
     }
 }
 

avatar image Psyrage · Aug 09, 2017 at 05:16 PM 0
Share

Remove score = 0; From Awake and add this below Update.

void OnLevelWasLoaded(int level) { Score$$anonymous$$anager.score = 0; }

Code is from this LInk: https://stackoverflow.com/questions/26934920/how-do-i-restart-my-score-reset-static-score-in-reloading-scene-in-unity

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by hbalint1 · Apr 03, 2015 at 08:17 PM

Hello. I asked a question recently. I think it will work for you as well.

http://answers.unity3d.com/questions/939809/find-uninstantiated-object-and-change-property.html

In the menu make the ScoreText to a public static string ScoreText; property and you can change it from other scene. So when the game ends you can change the text with ScriptName.ScoreText = score.ToString() and after Application.LoadLevel("Menu"); So it should display the latest score.

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 jcv8000 · Apr 03, 2015 at 08:08 PM

At the end of the game before it switches to the menu scene, you could use

PlayerPrefs.SetInt("Score", score);

And in the menu scene when you display the score use

text.text = PlayerPrefs.GetInt("Score");
or
text.text = PlayerPrefs.GetInt("Score").ToString();

I think they both work.

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

23 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

Related Questions

Carry over texts from one scene to another? 1 Answer

Score system 1 Answer

Scoring System between two different scene? 2 Answers

Why won't the Score reset? 2 Answers

Scene keeps reloading, can't keep score 3 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