Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question Help with Text Mesh Pro

Discussion in 'UGUI & TextMesh Pro' started by MagicFool64, May 5, 2023.

  1. MagicFool64

    MagicFool64

    Joined:
    Sep 23, 2019
    Posts:
    9
    Hi, I need help: I'm trying to make an RPG, but I have an issue.
    I start to say I used a Text Mesh Pro as text for selecting enemies. Do you know that text in RPG game, where you have to choose for selecting the target? Well, this is the full script for enemy buttons (I'm following xOctoManx tutorials)

    Code (CSharp):
    1.     void EnemyButtons()
    2.     {
    3.         foreach (GameObject enemy in EnemysInBattle)
    4.         {
    5.             GameObject newButton = Instantiate(enemyButton) as GameObject;
    6.             EnemySelectButton button = newButton.GetComponent<EnemySelectButton>();
    7.             EnemyStateMachine cur_enemy = enemy.GetComponent<EnemyStateMachine>();
    8.             Text buttonText = newButton.transform.GetChild("Text(TMP)").gameObject.GetComponent<Text(TMP)>
    9.             buttonText.text = cur_enemy.nemico.name;
    10.             button.EnemyPrefab = enemy;
    11.             newButton.transform.SetParent(Spacer);
    12.         }
    13.     }
    The text appeared as written "Text (TMP)", but it gives me an error. Can you help me?
     
  2. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,219
    Not until you explicitly state the message of the error. No, we do not care about the error number, only WHERE (in code) and WHAT (the text).
     
  3. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,196
    Always good to include your error.

    But, your variable type is Text. You might have meant TextMeshProUGUI as your variable type or TMP_Text. EIther way, you're not using the right variable type.

    I'm also not sure about the Text(TMP) and what you are trying to do with it. That isn't a valid TMP type. So again, you'll need to use one of the ones I mentioned above.
     
    Last edited: May 5, 2023
  4. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,219
    also this cannot possibly work
     
  5. miguel0l

    miguel0l

    Joined:
    Nov 10, 2021
    Posts:
    13
    To add on to this, since your script here is trying to make use of TextMeshPro, you'll need to add a
    Code (CSharp):
    1. using TMPro;
    at the top of your code along with the other namespaces, otherwise it might not work. I assumed you might not have that bit of code yet since your original code is using Text and TextMeshProUGUI etc.

    If it helps, this video could be useful for reference when you're working with TextMeshPro: