zahra
zahra

Reputation: 81

select and deselect object in unity3D

i am making a game in which i am using is-clicked function when i click the object the letter written on it displayed now i want that when i clicked the same object again the word disappear... now how can i do that?

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

Upvotes: 0

Views: 2305

Answers (1)

Dasu
Dasu

Reputation: 433

write in OnMouseDown

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

Upvotes: 2

Related Questions