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

Question TextMeshPro won't connect to my C# script element for a text display output

Discussion in 'Scripting' started by emevol4, May 4, 2023.

  1. emevol4

    emevol4

    Joined:
    May 29, 2022
    Posts:
    3
    I even used this basic script called HelloWorld, then attempted to attach a text element through the script component, I don't know what I am doing wrong? I am creating the text object in the scene, it will not attach to my player object nor the canvas object, how can something so simple, be so complicated, I created the public text variable, but I can't attach the text object to the variable. This is a Roll Result Text Prefab I am attempting to connect to the element I created in another script, I created to experiment with game design. when I click on the Text element, it says None under the Scene and Assets tabs.

    using UnityEngine;
    using UnityEngine.UI;

    public class HelloWorld : MonoBehaviour
    {
    public Text helloWorldText;

    private void Start()
    {
    helloWorldText.text = "Hello World";
    }
    }

    here's my player script
     

    Attached Files:

  2. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,043
  3. emevol4

    emevol4

    Joined:
    May 29, 2022
    Posts:
    3
    Hello, Thanks for the reply, I finally managed to fix this issue I was having. instead of using public text I was supposed to use TMP_Text in order for the text element to recognize Text Mesh Pro.

    public TMP_Text rollResultTextPrefab;

    private TMP_Text rollResultText;
     
    orionsyndrome likes this.