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 Teymur12 · Oct 28, 2020 at 01:54 PM · uitextupdate

How to add string once to the UI text, but update the substring every frame in unity?

Hello, I'm new to unity. I'm trying to show active effects in my game which player gained, and then show the effect name and time when the effect will finish in UI Text. But I have some problems. I created code example where you can understand better what I want.

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;

public class ActiveEffects : MonoBehaviour { public Text EffectsText; public GameObject ActiveEffectsPanel; public float olddaysnumber; public float sodarknumber; // Start is called before the first frame update void Start() { olddaysnumber = 1; sodarknumber = 1; }

 // Update is called once per frame
 void Update()
 {
     ShowActiveEffects();
 }
 void ShowActiveEffects()
 {
     ActiveEffectsPanel.SetActive(true);
     if (olddaysnumber == 1)
     {
         EffectsText.text += "Nostalgia" + "     " + (300f - OldDaysTime).ToString(); // I didn't assign time of the effect in this script to you to understand better what I want.
     }
     if (sodarknumber == 1)
     {
         EffectsText.text += "SoDark" + "     " + (300f - SoDarkTime).ToString(); // I didn't assign time of the effect in this script to you to understand better what I want.
     }
 }

}`

I have 2 effects. This is not the full code, because it's enormous, it's just piece of full code. When I run game I see this: /https://res.cloudinary.com/df9lgxsyr/image/upload/v1603868428/Hell_obuzq3.png I know where is the problem but I don't know how to solve it. I need to update the text once but the time I need to update must be updated every frame. Something like this: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;

public class ActiveEffects : MonoBehaviour { public Text EffectsText; public GameObject ActiveEffectsPanel; public float olddaysnumber; public float sodarknumber; public float stop; public float stop2; // Start is called before the first frame update void Start() { olddaysnumber = 1; sodarknumber = 1; stop = 1; stop2 = 1; }

 // Update is called once per frame
 void Update()
 {
     ShowActiveEffects();
 }
 void ShowActiveEffects()
 {
     ActiveEffectsPanel.SetActive(true);
     if (olddaysnumber == 1)
     {
         if (stop == 1)
         {
             EffectsText.text += "Nostalgia" + "     " + (300f - OldDaysTime).ToString(); // I didn't assign time of the effect in this script because it's script you to understand what I want.
             stop = 0;
         }
     }
     if (sodarknumber == 1)
     {
         if (stop2 == 1)
         {
             EffectsText.text += "SoDark" + "     " + (300f - SoDarkTime).ToString(); // I didn't assign time of the effect in this script because it's script you to understand what I want.
             stop2 = 0;
         }
     }
 }

}

But here the time updates only once but it must update every frame. And all effect's name and time must be written only in one UI Text. Does somebody know the answer? Thanks for help, Teymur, and sorry for my English.

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

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

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

Text Not updating 1 Answer

uGUI Text not updated until RectTransform has been altered 1 Answer

Text component changes the text but doesn't remove the previous version. 0 Answers

Multiple gui instantiation issues 0 Answers

Text UI not updating 2 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