0

我正在 unity3D 游戏引擎中制作文字游戏,如果单词拼写错误,我会创建一个单词我想从该单词中删除某个字符以进行正确的拼写,然后将其他字符移回...在我的代码中字符串并想从字符串中删除一个字符.... 这样当从字符串的中心删除字符时,其他字符就会移回。

static var nextPos = 200;
static var word: String;
var sel: String;
var isClicked : boolean=false;
var xpos: float = 200;
static var i:int=0;
function start()
{
 word="";
}
function OnMouseDown()
{
    if (!isClicked) {
       isClicked = true;
       xpos = nextPos;
       sel=OnGUI();
       word=word+sel;
       nextPos += 8;
       i++;

      }
else if(isClicked)
  {
  isClicked = false;
  xpos = nextPos;
  nextPos -= 8;

}
}
function OnGUI()
{  

   if (gameObject.name == "Sphere(Clone)" && isClicked )
   {
          GUI.Label(new Rect(xpos,260,400,100), "A");
          return "A";


   }

   else if (gameObject.name == "Sphere 1(Clone)" && isClicked )
   {
          GUI.Label(new Rect(xpos,260,400,100), "B");
          return "B";

   }  

   else if (gameObject.name == "Sphere 2(Clone)" && isClicked )
   {
          GUI.Label(new Rect(xpos,260,400,100), "C");
          return "C";

   }

  GUI.Label(new Rect(xpos,280,400,100), "Value" + i);
  GUI.Label(new Rect(xpos,300,400,100), word);                      
}
4

2 回答 2

0

显示文本后,您可以检查按下了哪个键

这应该工作。您只需在更新函数或 OnGUI 函数中调用它

如果在更新函数中使用“word”,请将其设置为全局变量

我把这个写出来了,它应该可以工作,很抱歉它有任何故障。

               if(Input.anyKey)
    {
            string letter = Input.inputString;
            if (word.Contains(letter))
{

word.Replace(letter,"");

}

    }
于 2013-11-09T23:25:50.130 回答
0

测试这个:

string value = "abcde";
string temp="";
temp = value.Substring(0, position - 1);
value = temp + value.Substring(position, value.Length);
于 2013-11-09T11:15:02.477 回答