Search Unity

Using TextMeshPro in Script

Discussion in 'Scripting' started by Divis10nStudios, Oct 13, 2018.

  1. Divis10nStudios

    Divis10nStudios

    Joined:
    Dec 26, 2017
    Posts:
    197
    i have an altimeter script but it uses the really blurred unity text but when i tried dragging the textmeshpro in it didn't let me.
    here's the script if it needs any changing.
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3.  
    4. using UnityEngine;
    5.  
    6.  
    7. using UnityEngine.UI;
    8.  
    9.  
    10. public class Altimeter : MonoBehaviour
    11. {
    12.  
    13.    
    14.  
    15.     public Text textFieldComponent; // Just select the text (not GUI text) field from the inspector.
    16.      void Update()
    17.         {
    18.          textFieldComponent.text = transform.position.y.ToString("00.00"); // Parameters in the ToString function formats the altitude to two decimal places.
    19.         }
    20.  
    21. }
    22.  
     
  2. If I remember well, it should be
    Code (CSharp):
    1. public TextMeshProUGUI textFieldComponent;
    And then, it will allow you to drop a textmeshpro ugui text component on it.

    But you need to match the type with the type of the thing you want to drop there, that is sure. If you want to use other type of element, you need to change that portion.