2013-11-04 57 views
0

我正在製作一個遊戲,其中我正在使用單擊功能,當我單擊對象時,它上面寫的字母顯示出來,現在我希望當我再次單擊相同的對象時,這個單詞消失..現在我該怎麼做?在unity3D中選擇和取消選擇對象3D

#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"); 
    } 
} 
+0

你在哪裏連接這個腳本?即哪個GameObject? – Dasu

+0

with sphere ..., – zahra

回答

2

寫在onmousedown事件

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

我希望在最後寫的字母只在點擊時沒有後面的字母才能刪除...爲了我該怎麼做 – zahra