Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Resolved GetComponent<TextMeshPro>().text ?

Discussion in 'UGUI & TextMesh Pro' started by CassioTDS, Nov 22, 2021.

  1. CassioTDS

    CassioTDS

    Joined:
    Jan 21, 2020
    Posts:
    12
    Hello, I was wondering how I could edit the text in a TextMeshProTextUI element since for me "TMP_Text","TextMeshProUGUI", "TextMeshPro", and "TMPro.TextMeshProUGUI" doesn't work.
    Example code:
    version = GameObject.Find("version").GetComponent<TMP_Text>().text;

    Thanks.
     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    In your script add a public field and then in the Inspector, assign the text object whose text property you want to change.

    Code (csharp):
    1.  
    2. public TMP_Text TextComponent;
    Then in your code, simply do TextComponent.text = "Some text";
     
    yigitcankorkmazer likes this.
  3. CassioTDS

    CassioTDS

    Joined:
    Jan 21, 2020
    Posts:
    12
    Somehow, I'm getting an error. It cannot find the type nor can it find something to import. upload_2021-11-22_20-18-52.png
     
    jbell_strong likes this.
  4. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    You need to add

    Code (csharp):
    1.  
    2. using TMPro;
    3.  
     
  5. CassioTDS

    CassioTDS

    Joined:
    Jan 21, 2020
    Posts:
    12
    I'm getting upload_2021-11-23_7-47-50.png .
     
  6. CassioTDS

    CassioTDS

    Joined:
    Jan 21, 2020
    Posts:
    12