我正在 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);
}