【发布时间】:2016-05-26 03:00:57
【问题描述】:
我一直在玩 Unity C# 中的文字游戏,但对于我想要实施的反作弊机制陷入了停顿。
在输入字段中输入第一个字母后,我开始运行 2 秒计时器。 2秒后,在玩家没有提交或输入另一个字母的情况下,输入字段应该将之前输入的字母锁定在输入字段的位置,之后输入的任何字母都应该在它之后输入。
这是我目前的代码:
currTime = 0;
hasInput = false;
lockedString = "";
void Update(){
if(hasInput){
currTime += Time.deltaTime * 1;
if(currTime >= 2){
//Stores current string value of input field
lockedString = inputField.text;
}
}
}
void OnInputValueChange(){
currTime = 0;
hasInput = true;
if(lockedString != ""){
inputField.text = lockedString + inputField.text;
}
}
现在,只要输入字段的值发生更改,我就会运行OnInputValueChange()。一旦计时器达到 2 秒,我还设法存储到目前为止输入的字符串,但我不知道如何做到这一点,以便输入字段将锁定的字符串“锁定”到前面并允许更改后面键入的字母它。每次更改值时,代码inputField.text = lockedString + inputField.text; 只是将lockedString 变量添加到输入字段。
期望的结果是这样的伪代码:
//User types "bu"
//2 second timer starts
//During these 2 seconds, user can delete "bu" or continue typing
//User deletes "bu" and types "ah"
//Once the 2 second timer ends, whatever string is now in input is locked
//"ah" is now locked at the front of the input field
//After locking "ah", user cannot delete it anymore, but can continue typing
任何关于我如何实现这样的目标的见解都会非常有帮助。感谢您抽出宝贵时间提供帮助,非常感谢!
【问题讨论】:
标签: c# unity3d input-field