Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question I can't drag my text into the editor slot!

Discussion in 'UGUI & TextMesh Pro' started by Loading7088, May 14, 2023.

  1. Loading7088

    Loading7088

    Joined:
    May 5, 2023
    Posts:
    9
    Hey all, I am trying to make text appear when I have a game over screen pop up. The buttons do, because they're dragged into the slots but the text wont let me drag it into the slot. The reference and the text are both TMPro, and I have TMPro in my script.
    Code (csharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Rendering;
    5. using UnityEngine.SceneManagement;
    6. using TMPro;
    7.  
    8. public class LogicScript : MonoBehaviour
    9. {
    10.     public GameObject gameOverScreen;
    11.     public GameObject continuePlaying;
    12.     public GameObject startButton;
    13.     public TextMeshPro gameOverText;
    14.  
    15.     private void Update()
    16.     {
    17.         currentTime = currentTime += Time.deltaTime;
    18.  
    19.         if (Input.GetKeyDown(KeyCode.Escape))
    20.         {
    21.             SceneManager.LoadScene(0);
    22.         }
    23.  
    24.     }
    25.  
    26.     public void restartGame()
    27.     {
    28.         SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    29.     }
    30.  
    31.     public void gameOver()
    32.     {
    33.         gameOverScreen.SetActive(true);
    34.         continuePlaying.SetActive(true); //This is a button, and for some reason even tho its TMP still uses the          //old SetActive method instead of enabled. Beware of that
    35.         gameOverText.enabled = true; //This is TMPro, so cant use SetActive?
    36.         baby.isAlive = false;
    37.  }
    I was gonna attach a video but it wont let ,me :/
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,969
    You need to use TMP_text or something similar. Now you reference the whole textmeshpro class instead of just the text you need.
    This is shown in documentation as well
     
  3. Loading7088

    Loading7088

    Joined:
    May 5, 2023
    Posts:
    9
    Can you give me a link to the unity docs? I cant seem to find the ones for TMP and where id put the TMP_text

     
  4. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,969
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,321
    The 2D forum is not for UI posts.

    I'll move your post to the UI forum.

    Thanks.