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 06, 2015 at 06:52 PM · android2dgameobjecttextscore

Carry over texts from one scene to another?

Hello. I am making a game that is 2D and for Android. I recently made a post asking how to set a score to zero using a button. Before the post, I made the score update every second and the text would carry over. Now the score is only updated every time you score a point, which is good, and pressing the button does make it to zero. The score does transfer over, but the text doesn't actually show it. What I mean is that it knows how many points are scored but the text just says New Text instead of saying Score: 24 ( For example ) What needs to be done for it to show the score instead of saying New Text?

The scoremanager script is

 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 ()
     {
         text = GetComponent <Text> ();
     }
     
     public void SetScore (int newScore)
     {
         ScoreManager.score = newScore; //update the static score variable
         text.text = "Score: " + score;
     }
 }

and the script that actually detects for a point to be added is

 using UnityEngine;
 using System.Collections;
 
 public class Score : MonoBehaviour {
     public int scoreValue = 1;
     public ScoreManager scoreManager;
     
 
     
     void OnMouseDown () {
         scoreManager.SetScore(ScoreManager.score + scoreValue);
     }
 }

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

so when you debug newScore after line 17 , do you get the updated "new score" ?

avatar image SUPPEAR · Apr 06, 2015 at 09:01 PM 0
Share

Yes I do. It's just that the script I am using only updates when a point is scored. Which means the text won't update when the scene changes. Unless somehow a point was added then it would show the score.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Digital-Phantom · Apr 06, 2015 at 07:16 PM

Just use DoNotDestroyOnLoad to carry the scoremanager object over from scene to scene.

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 SUPPEAR · Apr 06, 2015 at 08:43 PM 0
Share

Okay... I've done that. That doesn't change anything. I need to figure out a way for it to update the text to display the score. Since the text will only update if the score changes.

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

21 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

Related Questions

OnLevelWasLoaded script problem. 1 Answer

Score system 1 Answer

Why won't the Score reset? 2 Answers

Collision On Object Error. Please help. 1 Answer

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