Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug [Solved] TMPRO not working as expected

Discussion in 'UGUI & TextMesh Pro' started by AlexNikolay, Jul 13, 2022.

  1. AlexNikolay

    AlexNikolay

    Joined:
    Mar 1, 2022
    Posts:
    29
    Okay, so i want to make a UI that you can put the name of your buisness (using Input Field legacy) and then the name that you enter it will show to the van, and inside the van gameobject i inserted a Textmeshpro. So my issue is that i made a script that when you enter the name of your buisness it would show on the van but its not working. I think the issue is that legacy and textmeshpro arent compatible or something the error number line is 17. Here is the code:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using TMPro;
    6.  
    7. public class InputField : MonoBehaviour
    8. {
    9.     public string theName;
    10.     public GameObject inputField;
    11.     public TextMeshProUGUI textDisplay;
    12.  
    13.     public void StoreName()
    14.     {
    15.         theName = inputField.GetComponent<Text>().text;
    16.         Debug.Log(theName);
    17.         textDisplay.GetComponent<TMPro.TextMeshProUGUI>().text = ""+theName;
    18.     }
    19. }
    Can someone tell me what is going on? Thanks (sorry for my bad english)
     
  2. VRStudy

    VRStudy

    Joined:
    Oct 24, 2017
    Posts:
    10
    Try TextMeshProGUI.SetText(string):

    textDisplay.GetComponent<TextMeshProGUI>().SetText(theName);
     
  3. AlexNikolay

    AlexNikolay

    Joined:
    Mar 1, 2022
    Posts:
    29
    it works! thanks!
     
    VRStudy likes this.