需要帮助:我想比较两个InputFields 1,它显示一个数字; 1,用户可以在其中输入一个与显示内容进行比较的字母,然后显示字段会将颜色更改为右侧输入为绿色,而在右侧显示为红色。输入错误。 numEnemies显示意外的符号,并使用I <= 3要求将int解析为bool
public void InputCheking()
{
UserInput = inp2.text; // input field to get input from the user
for(int i = 0; i < numEnemies; i++)
{
switch (UserInput)
{
case "H":
CheckingForEight();
break;
case "U":
CheckingForTwentyOne();
break;
default:
Debug.Log("Default execute");
inp2.text = "";
break;
}
Debug.Log("Creating enemy number: " + i);
}
}
public void CheckingForEight()
{
//========================Taking Static
Debug.Log(inp1.text); // inp1 is an input field showing a perticular number gainst Alphabet such as 1 for A, 2 for B, and so on and so forth
if (UserInput == "H")
{
Debug.Log ("1st Phase");
inp1.text = "H";
inp1.image.color = Color.green;
inp2.text = "";
}
else
{
inp1.text = "8";
Debug.Log("2nd Phase");
inp1.image.color = Color.red;
}
}
public void CheckingForTwentyOne()
{
//========================Taking Static
Debug.Log(inp1.text);
UserInput = inp2.text;
if (UserInput == "U")
{
inp21.text = "U";// another input field that shows 21 against alphabet U
inp21.image.color = Color.green;
}
else
{
inp21.text = "21";
Debug.Log("Input In 2nd Phase");
inp21.image.color = Color.red;
}
}
答案 0 :(得分:0)
最后工作...
using UnityEngine;
using UnityEngine.UI;
public class Level_1 : MonoBehaviour {
string word = null;
int wordIndex = 0;
string alpha;
public InputField textBox = null;
[SerializeField] private float mainTimer;
public Text timerText;
public static float timer = 20f;
public Text resultText;
private bool canCounter = true;
private bool doOnce = false;
public InputField display8;
public InputField display21;
public InputField display12;
public InputField display11;
public InputField userInputField;
public string userEntry;
public void keyboardFunction(string alphabet){
wordIndex++;
word = word + alphabet;
textBox.text = word;
}
public void Okay()
{
InputCheking ();
}
public void ValueChangeCheck()
{
Debug.Log("Value Changed");
}
void Start () {
timer = mainTimer;
//numStart = (int)KeyCode.Alpha0;
}
// Update is called once per frame
public void Update () {
if (timer >= 0.0f && canCounter) {
timer -= Time.deltaTime;
timerText.text = timer.ToString("F");
}
else if (timer <= 0.0f && !doOnce){
canCounter = false;
doOnce = true;
timerText.text = "0.00";
timer = 0.0f;
SceneManager.LoadScene ("ResultScreen", LoadSceneMode.Single);
}
// Debug.Log ("Scene Lodaing after TimeUp!");
}
public void InputCheking()
{
userEntry = userInputField.text;
switch (userEntry)
{
case "H":
Debug.Log ("User put H");
display8.image.color = Color.green;
display8.text = "H";
userInputField.image.color = Color.white;
display8.DeactivateInputField ();
userInputField.text = "";
break;
case "U":
Debug.Log ("User put U");
display21.text = "U";
display21.image.color = Color.green;
userInputField.image.color = Color.white;
userInputField.text = "";
break;
case "L":
Debug.Log ("User put L");
display12.text = "L";
display12.image.color = Color.green;
userInputField.image.color = Color.white;
userInputField.text = "";
break;
case "K":
display11.image.color = Color.green;
display11.text = "K";
userInputField.image.color = Color.white;
userInputField.text = "";
Result ();
Debug.Log ("User put K");
break;
default:
Debug.Log ("Please Enter a correct Alphabet against Number");
userInputField.image.color = Color.red;
userInputField.text = "TRY AGAIN";
break;
}
}
public void Result()
{
if (display8.text == "H" && display21.text == "U" && display12.text == "L" && display11.text == "K") {
// DisplayComment.text = "Excellent";
Debug.Log ("Working");
}
else
{
userInputField.text = "Complete All Boxes";
}
}
}