在unity3D中选择并取消选择对象

时间:2013-11-04 09:00:43

标签: unity3d game-engine

我正在制作一个游戏,其中我使用点击功能,当我点击对象上显示的字母时,我现在想要当我再次点击相同的对象时,这个词就消失了......现在我该怎么办?是什么?

#pragma strict

static var nextPos = 200;
var word: String;
var sel: String;
var isClicked : boolean=false;
var xpos: float = 200;

function OnMouseDown()
{
    if (!isClicked) {
       isClicked = true;
       xpos = nextPos;
       nextPos += 8;

      } 
}
function OnGUI()
{  

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


   }

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

   }  

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

   }

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

1 个答案:

答案 0 :(得分:2)

写入OnMouseDown

else if(isClicked)
  {
  isClicked = false;
  // do your xpos stuff here
  }