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
1
Question by clcriado0 · Dec 20, 2019 at 12:39 AM · textupdatetextmeshstart

Why if I execute .SetText on the Start it dont works.

Hello, I want to execute in the Start of the script to set a text in to "texto", but when I execute it on Start dont works. If I use execute it on the Update it works but its no in the beginning, the update will send the messages 60frames x sec.

 using System.Collections;
 using System.Collections.Generic;
 using TMPro;
 using UnityEngine;
 
 public class ShowZenis : MonoBehaviour
 {
     // Start is called before the first frame update
 
     private ZeniManager zm;
     public TextMeshProUGUI texto;
     public int dinero;
     void Awake()
     {
             zm = gameObject.AddComponent<ZeniManager>(); //Instanciamos un nuevo objeto, en MonoBehaviour se instancian así.
             texto = (GameObject.Find("Monedas").GetComponent<TextMeshProUGUI>());
     }
     // Update es llamado una vez por cada frame.
     void Start(){
 
             dinero = zm.getZenis();
             texto.SetText("" + dinero);
     }
     public void OnClickIt() {
 
         if(gameObject.name == "ButtonAdd") {
 
             zm.addMoney(40);
             dinero = zm.getZenis();
             texto.SetText("" + dinero);
             //PlayerPrefs.DeleteAll();
         }
     }
 }
 

IF I USE START: alt text

 using System.Collections;
 using System.Collections.Generic;
 using TMPro;
 using UnityEngine;
 
 public class ShowZenis : MonoBehaviour
 {
     // Start is called before the first frame update
 
     private ZeniManager zm;
     public TextMeshProUGUI texto;
     public int dinero;
     void Awake()
     {
             zm = gameObject.AddComponent<ZeniManager>(); //Instanciamos un nuevo objeto, en MonoBehaviour se instancian así.
             texto = (GameObject.Find("Monedas").GetComponent<TextMeshProUGUI>());
     }
     // Update es llamado una vez por cada frame.
     void Update(){
 
             dinero = zm.getZenis();
             texto.SetText("" + dinero);
     }
     public void OnClickIt() {
 
         if(gameObject.name == "ButtonAdd") {
 
             zm.addMoney(40);
             dinero = zm.getZenis();
             texto.SetText("" + dinero);
             //PlayerPrefs.DeleteAll();
         }
     }
 }

IF I USE UPDATE:alt text

You will say me: use the Update, but the problem is when I use the Update I cant modify the text, like its forever don't know how to say it.

Thanks.

Comment
Add comment · Show 1
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 Anis1808 · Dec 20, 2019 at 02:11 PM 0
Share

Have you tried texto.text = "" + dinero; ins$$anonymous$$d of texto.SetText("" + dinero); ?

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Statement · Dec 20, 2019 at 02:36 PM

Perhaps something else sets the text of texto after you have set it, overriding your text. I don't recall if you could change the Script Execution Order of Start calls.

Also you could do an if (!loadedTexto) { loadedTexto = true; texto.SetText("" + dinero); } where you set the value once in Update. A bit of a hack, but should do it.

Comment
Add comment · Show 2 · 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 clcriado0 · Dec 20, 2019 at 05:27 PM 0
Share

thanks you, fixed it!

avatar image Statement clcriado0 · Dec 20, 2019 at 05:38 PM 0
Share

I changed my comment to an answer and marked it as accepted for you.

Please unaccept if you feel there is a better answer.

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

127 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

Related Questions

Realtime clock 3 Answers

Start, Awake, Update. Any other ways to call functions from an empty GameObject? 3 Answers

textmeshproUGUI.rebuild() Lag on mobile devices 0 Answers

How to change text on a TextMesh with a non-dynamic font on iOS? 2 Answers

Putting text on a 3D object? 3 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