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 Dgrohl91 · Jun 05, 2016 at 05:59 PM · uitextcoroutinesfor

Making a growing number

Hi everyone

I want to make some kind of presentation with Unity, this project includes numerical statistics so I want to make them look alive with the growing "animation". My problem is that even with a Coroutine this number is shown instantly.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class grownumber : MonoBehaviour {
     public int limit;
     private int counter;
     private Text text_n;
     // Use this for initialization
     void Start () {
         text_n = GameObject.Find ("number").GetComponent<Text>();
         counter = 0;
         limit = 60000;
     }
     
     // Update is called once per frame
     void Update () {
         
     }
 
     void grow(){
         
         for(int i=0;i<limit;i++){
             StartCoroutine ("count");
         }
     }
 
     void OnTriggerEnter (Collider other){
         if (other.tag == "Player") {
             print ("collider");
             grow ();
         }
     }
         
     IEnumerator count(){
         yield return new WaitForSeconds (0.5f);
         counter+=1;
         text_n.text = ""+counter+"";
     }
 }
     

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 Mmmpies · Jun 05, 2016 at 07:12 PM

How about adding the start time in start and if Time.time > Starttime + 0.5f show text.

 private float StartTime;
 private bool shownText =false;
 
 void Start(){
      StartTime = Time.time;
 
 
 void Update(){
      if(Time.time > StartTime + 0.5f && shownText == false)
      {
           ShowTextFunction();
           shownText = true;
      }

Should work and if you want to do it every .5 seconds just have that function reset StartTime and the bool to false.

Comment
Add comment · Show 4 · 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 Dgrohl91 · Jun 05, 2016 at 08:35 PM 0
Share

I get the same result, but thanks. $$anonymous$$aybe I've misunderstood your message. $$anonymous$$y code now look like this:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class subircifra : $$anonymous$$onoBehaviour {
     public int limite;
     private int contador;
     private Text texto;
     private float startTime;
     private bool shownText;
     // Use this for initialization
     void Start () {
         text_n = GameObject.Find ("50$").GetComponent<Text>();
         counter = 0;
         limit = 60;
         startTime = Time.time;
     }
     
     // Update is called once per frame
     void Update () {
         if(Time.time > startTime + 0.5f && shownText == false){
             text_n.text = ""+counter+"";
         }
     }
 
     void grow(){
         while (counter < limit) {
             counter++;
         }
         
     }
 
     void OnTriggerEnter (Collider other){
         if (other.tag == "Player") {
             print ("collider");
             grow ();
         }
     }
 }
     
avatar image kristof1104 Dgrohl91 · Jun 05, 2016 at 08:43 PM 0
Share

try changing the grow function to:

 void grow(){
       counter++;
 }

avatar image Dgrohl91 kristof1104 · Jun 05, 2016 at 08:50 PM 0
Share

But if I do so, the counter will be increased without a limit, and I have a goal so to speak

Show more comments

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

77 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

Related Questions

Get height of text with given width. 0 Answers

Text not showing in build (but the rest of UI shows up) 1 Answer

NullReferenceException on Text element 1 Answer

Text Mesh pro won't show certain characters 1 Answer

Text won't properly update in Unity Bolt 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