Question by
GamersFrenzy · Jul 26, 2016 at 07:04 AM ·
c#ifonclicktruegetmousebuttondown
How to return back to false?
I'm having an issue on simple code. I have a public bool variable that is set to false at runtime. I want to set up an OnClick or Clickable method that, once clicked, switches the variable to true in which I can get it to work fine. The issue that I am having is switching it back to false on a second click. I trued the IPointerClickHandler interface and got nowhere then attempted to use the Input.GetMouseDown function and I still can't seem to figure it out. Am I going about his the wrong way. How would you guys go about it?
public void Update(){
if (Input.GetMouseButtonDown (0)) {
if (!selected) {
}
selected = true;
}
}
}
Comment
Answer by andrei2699 · Jul 26, 2016 at 09:39 AM
Try this :
public void Update()
{
if (Input.GetMouseButtonDown (0))
{
selected = !selected;
/*
Or the longer version
if (selected)
{
selected = false;
}
else
{
selected = true;
}
*/
}
}