1

Hi I am trying to make some popup instructions I want to disable the text when the person presses a key how might I do that?

Lumic
  • 39
  • 3
  • 8

2 Answers2

3
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI; // Namespace for Unity's UI system

public class EnableAndDisableText : MonoBehaviour {
    [SerializeField] Text text; // Text that you want to disable

    private void Update() // Called every frame
    {
        if (Input.GetKeyDown(KeyCode.E)) // If the 'E' key is pressed,
        {
            text.enabled = false; // Disable text
        }
    }

}
Easwar Chinraj
  • 436
  • 1
  • 4
  • 10
MysticalUser
  • 404
  • 5
  • 13
  • I got a error ```error CS0116: A namespace cannot directly contain members such as fields or methods``` – Lumic Aug 09 '20 at 04:55
1

Maybe text.SetActive(false); could work? or Destroy(text);?

I see the question is 3 months old but I hope this still helps;

Ghost
  • 735
  • 5
  • 16
Daki
  • 36
  • 5