c# - 互动游戏:以下代码有错误 Unexpected symbol `)',期望 `;' 或`}'
问题描述
需要帮助:我想比较两个 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;
}
}
解决方案
终于上班了......
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";
}
}
}
推荐阅读
- angular - 如何在 Angular 2+ 中基于组件创建模板?
- python-3.x - 在 igraph 上使用 cairo 绘图时出错:模块 'cairo' 没有属性 'Surface'
- join - awk 匹配/比较/每个文件中的 2 列(对于 2 个文件)
- geocoding - 您已超出此 API 的每日请求配额。甚至使用 api 密钥
- spring - 无法代理接口实现方法 [public final void AbstractTestNGSpringContextTests.setApplicationContext()]
- vba - 通过输入框输入的数字未链接到我在 B 列中的公式
- ruby - 如何使用 selenium 网格对 appium 运行并行测试?
- angular - 根据从另一个 primeNg 多选下拉列表中选择/取消选择的值,从 primeNg 多选下拉列表中添加/删除项目/值
- objective-c - NSTableView 在屏幕外隐藏行
- c# - 字符串替换,在 LINQ 查询中从另一个值中删除一个值