Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Using TextMeshPro in Script

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

  1. PixelCloudInc

    PixelCloudInc

    Joined:
    Dec 26, 2017
    Posts:
    48
    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. LurkingNinjaDev

    LurkingNinjaDev

    Joined:
    Jan 20, 2015
    Posts:
    830
    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.