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 /
avatar image
0
Question by AngryAtNothing · Sep 15, 2016 at 12:46 PM · unity 5uibuild2d gamebeginner

Unity 5.4.0f3 Personal - UI not updating after Build.

I'm still a complete scrub when it comes to all of this and I am having an issue with my UI once the game has been built. I'm building a Pong clone which is designed to increment a score based on which goal the game ball enters and it works fine in the editor. But as soon as I build the game and test it the UI will not update.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 using UnityEngine.SceneManagement;
 
 public class Score : MonoBehaviour {
 
     private int CurrentScore;
     private int CurrentAIScore;
 
     public Text PlayerText;
     public Text AIText;
 
     public GameObject sceneManager;
 
     void Update()
     {
         PlayerText.text = CurrentScore.ToString ();
         AIText.text = CurrentAIScore.ToString ();
     
     }
 
     void OnTriggerEnter2D(Collider2D DoesScore)
     {
         if (DoesScore.gameObject.tag == "Player" && DoesScore.gameObject.isStatic) 
         {
             CurrentScore++;
             Debug.Log ("Player Scored!");
             if (CurrentScore >= 9) 
             {
                 SceneManager.LoadScene ("PlayerWins");
             } 
         }
         if (DoesScore.gameObject.tag == "AI" && DoesScore.gameObject.isStatic) 
         {
             CurrentAIScore++;
             Debug.Log ("AI Scored!");
             if (CurrentAIScore >= 9) {
                 SceneManager.LoadScene ("AIWins");
             }
         }
     }
 }
 

All tags are correctly wired up, triggers are active on the box colliders of the goals and are set to static. The score even initializes at '0' for both players as it writes it in update(). I think it might have something to do with either the SceneManager or the Triggers. Im just not sure. Any help would be greatly appreciated.

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 DenisTribouillois · Sep 15, 2016 at 12:58 PM

You should update the texts when the score changes, not in Update, since it will be called each frame, even if the score doesn't change.

 void Awake()
      {
          PlayerText.text = "0";
          AIText.text = "0";
      }
 
 void OnTriggerEnter2D(Collider2D DoesScore)
      {
          if (DoesScore.gameObject.tag == "Player" && DoesScore.gameObject.isStatic) 
          {
              CurrentScore++;
              PlayerText.text = CurrentScore.ToString ();
              Debug.Log ("Player Scored!");
              if (CurrentScore >= 9) 
              {
                  SceneManager.LoadScene ("PlayerWins");
              } 
          }
          if (DoesScore.gameObject.tag == "AI" && DoesScore.gameObject.isStatic) 
          {
              CurrentAIScore++;
              AIText.text = CurrentAIScore.ToString ();
              Debug.Log ("AI Scored!");
              if (CurrentAIScore >= 9) {
                  SceneManager.LoadScene ("AIWins");
              }
          }
      }

Your piece of code should work tho...

Do the triggers work properly (--> you get the Debug.Log) and only UI is affected ?

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 AngryAtNothing · Sep 21, 2016 at 07:04 PM 0
Share

Sorry about the late reply. I'm not sure what I did exactly, because I can no longer access my original games files. I transferred them into another folder than than exporting it and I haven't been able to get it to work since. But since this happened I have been playing around with other projects and I believe the original problem simply stemmed from me not always hitting apply to prefab changes. I can't confirm this at this current time, but I'm 90% sure that's what caused the issue.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Getting Error wheni build and run my game, couldn't swtich to requested monitor resolutuon swtiching to 1080x1920 or 1024x768,Help anyone? 0 Answers

problem with Text UI when debugging on android 1 Answer

When using unet to spawn players, the player object is invisible, but colliders present. Help 0 Answers

Distribute terrain in zones 3 Answers

Problem with build version 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