I have in my hierarchy tab a Canvas. Inside the canvas I have an Input Field that holds a placeholder and a text.
I read the documentations and didn't find how to hide the Input field.
I want that if a if
statement is true, then it will show the input field. Else you won't see it.
How can I implement it?
EDIT
I thought about an idea to test: If I press the O key on the keyboard it disappears, and if I press again it appears; and so on.
This is what I tried:
bool shown = true;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
GameObject inputField = GameObject.Find("InputField");
if (Input.GetKeyDown (KeyCode.O)) {
shown = !shown;
inputField.SetActive (shown);
}
}
I play the scene and when I press the O key I get
NullReferenceException: Object reference not set to an instance of an object
If I double-click on the console message it highlights me the if (Input.GetKeyDown (KeyCode.O)) {
line.
Something not good does the SetActive(bool)
method, I suppose.