Hello i just want to make the input button disabled in unity engine if there is no text in the text input field. it seems that the if statement in update method does not check if there is any text in the textfield. please help me with this. i also tried to use: if ... Frage=""; but it also not working here is my code so far and thanks for any help:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ParaTalk : MonoBehaviour
{
public Text TextAntwort;
public string Frage;
public GameObject textFrage;
public GameObject textAnzeigen;
public Button frageStellen;
private void Start()
{
frageStellen.enabled = true;
textFrage.GetComponent<Text>().text = Frage;
}
private void Update()
{
if (string.IsNullOrWhiteSpace(Frage))
{
frageStellen.enabled = false;
}
else
{
frageStellen.enabled = true;
}
}
// Random Text Output
public void SetText(string text)
{
string[] sonstiges = new string[] { "grasslands", "rainforest", "desert", "rocky", "swamp", "tundra" };
System.Random random = new System.Random();
int useWords = random.Next(sonstiges.Length);
string pickWords = sonstiges[useWords];
TextAntwort.text = pickWords;
print(pickWords);
}
// Frage anzeigen
public void FrageSpeichern()
{
Frage = textFrage.GetComponent<Text>().text;
textAnzeigen.GetComponent<Text>().text = Frage;
}
}