• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Change the content of a Text Mesh 1 Answer

Insert 3d text to the front face of a cube GameObject 0 Answers

Update scene every 5 minutes 2 Answers

Adding vertices to TextMesh Pro 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges