如何检查InputField.Text是否包含两个随机生成的字母


using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Security.Cryptography.X509Certificates;
using UnityEngine;
using UnityEngine.UI;
public class LetterRandomiser : MonoBehaviour
{
public char[] characters; 
public Text textbox; 
public InputField mainInputField;
void Start() /*when the game starts*/
{
char c = characters[Random.Range(0,characters.Length)];
textbox.text = c.ToString(); 
}
void Update()
{
if (Input.GetKeyDown(KeyCode.KeypadEnter) && mainInputField.text.Contains(textbox.text) == true)
{
char c = characters[Random.Range(0, characters.Length)];
textbox.text = c.ToString();
mainInputField.text = "";
}
else if (Input.GetKeyDown(KeyCode.KeypadEnter) && mainInputField.text.Contains(textbox.text) == false)
{
mainInputField.text = "";
}
}
}

参考我的游戏

我正在尝试对我的游戏进行编程,这样两个文本框(firstChar和secondChar(将分别选择一个随机生成的字母。

然后,当玩家在输入框中键入一个单词时,游戏会检查该单词是否包含随机生成的两个单词。

如果是这样,那么程序将再次随机化两个文本框,并且输入字段将为空。

否则程序将不会随机化这两个文本框,玩家将不得不再试一次。

但是程序不起作用。没有错误,但当我按下回车键时,什么都没有发生,就像图像上显示的那样。

由@DerDingens回答。

您正在检查KeypadEnter。正常/大回车返回:docs.unity3d.com/ScriptReference/KeyCode.KeypadEnter.html.

最新更新