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. Dismiss Notice

How do I change the properties of "TextMeshPro" on a GameObject?

Discussion in 'Scripting' started by Bigmancozmo, Feb 24, 2021.

  1. Bigmancozmo

    Bigmancozmo

    Joined:
    Sep 13, 2020
    Posts:
    17
    I have a game object which has the "TextMeshPro" component. The object is needed for the game to function correctly, and its text needs to be changed throughout the game.
    Basically:
    I need to change the text that is displayed on an empty gameobject with the TextMeshPro component
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,755
    When? At editor time? You can just do it in the editor. Or you can write an editor script that does it.

    At runtime? You can write a script to scan the scene for the TextMeshPro component you seek and manipulate properties on each instance it finds.

    The editor script mentioned in the first line above could use a lot of the code from the second line. The suite of various GetComponent methods will find stuff for you.

    What exactly are you trying to do? If you're just trying to put a text label over certain types of objects in your games, there's some tutorials on Youtube about doing this with various approaches like character names and health bars.
     
  3. Bigmancozmo

    Bigmancozmo

    Joined:
    Sep 13, 2020
    Posts:
    17
    Ok, thanks.
    Also I'm doing runtime btw.