Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by BeanSlice · Jul 24, 2017 at 05:39 PM · uierrorbuildtextcounter

In-game counter stops counting when game is built?

Thanks for reading my message. In my game, I have a counter set up which displays the number of checkpoints in my level, and when the player reaches each checkpoint, the counter deducts 1 from the count. this works perfectly in the editor as well as when the game is built but once you die and the level is restarted, then the counter will never count down. What is confusing me is that this is only a problem once the game is built, not in the editor (which runs exactly how I anticipated). any help will be appreciated! The script below is being used by other scripts, but literally just to enable/disable it (for instance, when the player dies, I use "counter.enabled = false" to hide the counter, then the player can press the restart button, then the counter is shown upon the reloaded level if that makes sense)

Here is the counter script: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;

 public class Count : MonoBehaviour 
 {
     public Text counterText;
     public int numberOfCheckpoints;
 
     void Start ()
     {
         SetCountText ();
     }
 
     void OnTriggerEnter (Collider other)
     {
         if (other.gameObject.CompareTag ("Checkpoint")) 
         {
             numberOfCheckpoints = numberOfCheckpoints - 1;
             SetCountText ();
         }
     }
 
     void SetCountText ()
     {
         counterText.text = "Checkpoints: " + numberOfCheckpoints.ToString ();
     }
 }
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by alankemp · Jul 24, 2017 at 08:00 PM

Do you ever set numberOfCheckpoints back to its starting value when the player presses the restart button?

You could add another member variable for the maximum number of checkpoints and set numberOfCheckpoints equal to that when the level starts.

If you are enabling/disabling the counter when the game starts and ends you could use the OnEnable() function instead of Start():

  public class Count : MonoBehaviour 
  {
      public Text counterText;
      public int numberOfCheckpoints;
      public int maxNumberOfCheckpoints;
  
      void OnEnable()
      {
          numberOfCheckpoints = maxNumberOfCheckpoints;
          SetCountText ();
      }
 
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

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

Related Questions

Creating multiple text components on a canvas 1 Answer

i cant put text into a ui text thru a c# script 0 Answers

Help! Unity does not include all of my UI elements in the apk file! [SOLVED] 1 Answer

a ton of cs0246 errors on scripts that arent even mine, that happened out of nowhere 0 Answers

Canvas Renderer event 0 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