Use variable to Open/Close door depending on its last state?

I think im close here, but if there is a better way to go about this, im all ears. I want to play the door open animation first, if its not already open. Then when you are ready to close it, you click again and it closes. This is what i have so far.

var rd2 = 0;

function OnMouseDown () {
	if (rd2 = 0) {
		iradar_reardoor2=GameObject.Find("radar_reardoor2"); 
		iradar_reardoor2.transform.animation.Play("radar_reardoor2Open");
		rd2 = 1;
	}else{
		iradar_reardoor2=GameObject.Find("radar_reardoor2"); 
		iradar_reardoor2.transform.animation.Play("radar_reardoor2Close");
		rd2 = 0;
		}
}

Im getting errors,

found ‘=’
Unexpected token: 0
found ‘=’

What do you think? Am i missing just a few little characters here and there, or am i going about this the wrong way.

try use

var rd2 = 0; 

function OnMouseDown () { 
   if (rd2 == 0) { 
      iradar_reardoor2=GameObject.Find("radar_reardoor2"); 
      iradar_reardoor2.transform.animation.Play("radar_reardoor2Open"); 
      rd2 = 1; 
   }else{ 
      iradar_reardoor2=GameObject.Find("radar_reardoor2"); 
      iradar_reardoor2.transform.animation.Play("radar_reardoor2Close"); 
      rd2 = 0; 
      } 
}

Ahhhhh ok. What exactly does == mean? is it more like a question? “If its equal to 0”

Thanks for your help!

Did it work ?

I really don’t know myself, but I think that if you use one = you tell the computer that you change variable 1 to variable 2 like if button pressed var1 = var2

but if you want to compare to variables you use ==
if var1 == var2 do somethin, I think ??? :smile:

Oh yes it worked perfectly!

I see what your saying, its more of a comparison. Makes sense. Thanks for your help again :slight_smile: