Search Unity

Question My script does not accept TextmeshPro texts

Discussion in 'Scripting' started by LetmeDwight, Dec 20, 2020.

  1. LetmeDwight

    LetmeDwight

    Joined:
    Apr 9, 2020
    Posts:
    125
    So far I've only managed with ordinary lyrics. I have a period stand where a word: "You:" is joined together with an int value. That has worked well so far, but how do I do it now if I want to overwrite a TextMesh Pro text with: "You:" and the int value? What do I have to change in my current script so that the script also addresses textmesh pro texte? Because so far nothing happens when I combine the text mesh pro text in the game object ...

    This is my current script, which has always worked well so far when it comes to normal texts:
    What do I have to change so that the same goes with TMP texts?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class Punktestand_Player_Memory : MonoBehaviour
    7. {
    8.     Text text_punktestandplayer;
    9.  
    10.     private void Start()
    11.     {
    12.         text_punktestandplayer = GetComponent<Text>();
    13.     }
    14.     private void OnEnable()
    15.     {
    16.         text_punktestandplayer = GetComponent<Text>();
    17.     }
    18.  
    19.  
    20.     // Update is called once per frame
    21.     void Update()
    22.     {
    23.         // Sucht sich den int wert aus dem memory_runtime script raus um dann den int wert dieser ui text anzuhaengen...
    24.         Runtime_Memory Runtime_MemorySCRIPT;
    25.         Runtime_MemorySCRIPT = GameObject.Find("panel_Memory").GetComponent<Runtime_Memory>();
    26.  
    27.         text_punktestandplayer.text = "You: " + Runtime_MemorySCRIPT.punkte_spieler;
    28.     }
    29. }
    30.  
     
    ariktalko and Cheryl8088 like this.
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,910
    Add:
    Code (CSharp):
    1. using TMPro;
    at the top of your file and change
    Text
    to
    TMP_Text
    .
     
  3. LetmeDwight

    LetmeDwight

    Joined:
    Apr 9, 2020
    Posts:
    125
    ERROR.
    Error CS0118 'TMPro' is a namespace but is used like a type

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using TMPro;
    6.  
    7. public class Punktestand_Player_Memory : MonoBehaviour
    8. {
    9.     TMPro text_punktestandplayer;
    10.  
    11.     private void Start()
    12.     {
    13.         text_punktestandplayer = GetComponent<Text>();
    14.     }
    15.     private void OnEnable()
    16.     {
    17.         text_punktestandplayer = GetComponent<Text>();
    18.     }
    19.  
    20.  
    21.     // Update is called once per frame
    22.     void Update()
    23.     {
    24.         // Sucht sich den int wert aus dem memory_runtime script raus um dann den int wert dieser ui text anzuhaengen...
    25.         Runtime_Memory Runtime_MemorySCRIPT;
    26.         Runtime_MemorySCRIPT = GameObject.Find("panel_Memory").GetComponent<Runtime_Memory>();
    27.  
    28.         text_punktestandplayer.text = "You: " + Runtime_MemorySCRIPT.punkte_spieler;
    29.     }
    30. }
    31.  
     
    ariktalko likes this.
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,910
    Read my comment again! Specifically this part:
     
  5. LetmeDwight

    LetmeDwight

    Joined:
    Apr 9, 2020
    Posts:
    125
    now it works!
    thanks.
     
    ariktalko likes this.