Search Unity

  1. Unity 2018.3 is now released.
    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. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Nominations have been announced for this years Unity Awards. Celebrate the wonderful projects made by your peers this year and get voting! Vote here!
    Dismiss Notice
  6. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Using TextMeshPro in Script

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

  1. PixelCloudInc

    PixelCloudInc

    Joined:
    Dec 26, 2017
    Posts:
    54
    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:
    1,937
    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.