Object won't reactivate or activate with button press.

I am using a script to activate an object when I press “b”.If the object is active it will deactivate if I press be but will never activate or reactivate. What am I missing here? I put the object in the variable buildMenu. It is a simple plane with a text on it and box collider.

var buildMenu : GameObject;
var menuActive = false;

function Start()
{
	menuActive = false;
}

function Update () 
{
	if (Input.GetKeyDown ("b"))
	{		
		if (menuActive == false)
		{
			buildMenu.SetActive(true);
			menuActive = true;
			Debug.Log("Menu Active");
		}
		if (menuActive == true)
		{
			buildMenu.SetActive(false);
			menuActive = false;
			Debug.Log("Menu Not Active");
		}
	}	
}

Certainly, at you it to turn out nothing because two of your conditions are satisfied one after another in one frame. I will a little correct your script:

 function Update () {
  if (Input.GetKeyDown (KeyCode.B)) {       
   if (menuActive == false) {
    buildMenu.SetActive(true);
    menuActive = true;
    Debug.Log("Menu Active");
   } else {
    buildMenu.SetActive(false);
    menuActive = false;
    Debug.Log("Menu Not Active");
   }
  }   
 }

I hope that it will help you.

If the script is on the object itself, it will not reactivate because the very script that you are trying to access is not active.

You must access this script from another script.

Put this script on another GameObject in your scene, and activate it using references. (i.e. put it on a parent of the object, or find the object using GameObject.Find (" ").GetComponent<>();