- Home /
Click ui text to dissapear in 3D unity 2017 first person game script for ui multiple texts?,Clicking Text away in Unity 2017 3D first person game
Hello. I am relatively knew to unity, and I am creating a 3D unity game that is first person character. I have text I would want for the player to click on, after reading, so the text would disappear. I have the coding for a keyboard click to have the text disappear (for good from the game) once a player reads it, they click down on the keyboard. Here is the code I am working with and it works however there is a problem....... code:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class TextClick : MonoBehaviour { public Text text;
void Update() {
if(Input.GetKeyDown("q"))
{
this.gameObject.SetActive(false);
}
}
}
The problem I am having is that I have multiple texts that I would like to use the same code for. So once a player reads it, they click down on the keyboard key that I have shown in the code. However, as much as it does work, I am finding out that all the text is disappearing once you click that key, even the text not seen in the gameplay yet.
The text is a crucial part of my game and is needed. So is there a code to use the same script on multiple objects at different times? The objects are UI texts labeled as Text_1 and Text_2 and so on.
What would be the coding I would need? Thanks for the help.