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 GregPDesUGD · Oct 03, 2016 at 01:44 AM · uitextscorefunctionsupdate function

In updating some score text, why should we use the Update function instead of separate functions?

I'm following the tutorials for Survival Shooter, and there's something that made me want to ask from the "Scoring points" video.

I noticed that in the ScoreManager script, the Update function is used to change the text for the ScoreText object in the hierarchy. Question is, what other benefits does it bring other than simply making text updates simpler?

In this script for my Pong clone, I have two functions that update the text for the player scores: outputPlayerGoals and outputOpponentGoals. Aside from initializing them in the Start function, they are not called by the Update function. Instead, they are called from incrementPlayerGoals and incrementOpponentGoals respectively, which are called from OnCollisionEnter in Ball.cs.

I simply feel that using the Update function to update the score text would not be an efficient approach. Or perhaps I am thinking too much of pre-optimization and not refactoring and post-optimization as I go?

Comment
Add comment · Show 4
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 TBruce · Oct 03, 2016 at 01:55 AM -1
Share

There is always more than one way to do something. This is just the way that the developer did this. Usually everyone who goes through the tutorials ends up finding ways to do things differently depending on how they want to modify it.

The tutorial is also meant to show you that a game can, and usually is, comprised of several components. In this case one of the components is a Score$$anonymous$$anager.

avatar image pfreese · Oct 03, 2016 at 06:25 PM 1
Share

The Text component checks to see if you are changing the text to an identical string and if so, does nothing, so it's not terribly inefficient to replace the string in every Update call. On the other hand, it might make more sense in your code to do some additional processing when the score changes, such as play a sound effect or animate the score, in which case it makes sense to just change the text as part of this process.

avatar image GregPDesUGD pfreese · Oct 04, 2016 at 02:21 AM 0
Share

That's what I figured. Changing the text itself is sufficient. But have the audio be called to play per frame? That doesn't fit.

avatar image pfreese GregPDesUGD · Oct 05, 2016 at 04:24 PM 0
Share

I think you misunderstand. $$anonymous$$y example of playing audio would be when you have some sort of score manager, in which when the score changes, some additional processing might deter$$anonymous$$e whether to play a sound and what type, along with storing the new text string -- i.e., not in the Update function.

0 Replies

· Add your reply
  • Sort: 

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

103 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

Related Questions

Is it possible for camera to detect a collision between 2 different objects it's looking at? 0 Answers

UI text script working on an object but not working on copied object 0 Answers

I have a score displayed constantly in my game, but I can't get it to work for my game-complete screen? Help? 0 Answers

Can't update score text - small error breaks the game (Space Shooter Tutorial) 1 Answer

How to change the text inside UI>Text 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