Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Text in TextMeshProUGUI is not visible in GameView

Discussion in 'UGUI & TextMesh Pro' started by karthimitelex, Feb 24, 2024.

  1. karthimitelex

    karthimitelex

    Joined:
    Jan 26, 2024
    Posts:
    2
    Hi,
    I'm pretty new to both Unity and Coding. I'm trying to add Text once a particular gameObject gets connected to its source and display the distance.
    Here's what I'm trying to do.
    1) I have a preFab created which is just an empty object (layer UI) with a sprite renderer (sprite attached) - no script attached
    2) When a hit is detected,

    #####
    instance = Instantiate(preFabTextToSpawn, scoreBoardLocation, Quaternion.identity);
    TextBoxObject = instance.AddComponent<TextMeshProUGUI>();
    TextBoxObject.text = tapProperties.myNodeName.NodeName;
    #####

    During the gameplay,
    I see the clone of the preFab getting created, the sprite shows up in the game view. But not the Text.
    In the scene view, I see the sprite and a box showing "T"

    View attachment 1375616


    In the inspector, I see the actual text to be displayed
    View attachment 1375619

    I'm not sure what I'm missing here.
    I added the sprite just to check whether the display in game view comes out for the object. Eventually, it should be just text.

    Main camera : Clipping Plane near is set to -100 and Far 1000

    Any help is much appreciated.

    Thanks !
    KK
     
  2. karthimitelex

    karthimitelex

    Joined:
    Jan 26, 2024
    Posts:
    2