I m trying to make a UI text element appear on button click and then disappear after 5 seconds. However, the text does not appear on button click.
Code attached below for reference.
Where am I going wrong ? What s the best solution ?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class Recording : MonoBehaviour
{
public TextMeshProUGUI recordingText;
void Start()
{
recordingText.enabled = false;
}
public void DisplayText(string text)
{
recordingText.text = text;
recordingText.enabled = true;
Invoke("DisableText", 5f);
}
void DisableText()
{
recordingText.enabled = false;
}
}