Command "GetButton" not working well

I was making a Firethrower script on JavaScript, and I read that the command “GetButton” sets “true” when the key is holded, and sets “false” when not. But in my case, when I press the key, becomes “true”, and doesn’t come false never. There’s the code:

51174-2015-07-28-174852.png

PS: Sorry for my English.

You need to handle the false condition to set the flameThrower back to inactive…

if (Input.GetButton("Fire1"))
{
  flameThrower.SetActive(true);
}
else
{
  flameThrower.SetActive(false);
}

The code you have now is activating the flamethrower when the button is first pressed, but you don’t have anything to deactivate it. When GetButton returns false in my sample code, flameThrower will be set to inactive.

You can shorten this up a bit by just passing the boolean result of GetButton directly to the SetActive method.

flameThrower.SetActive(GetButton("Fire1"));

But whether or not you want to do that depends on if you have other things to do with the button is held down or not.

If I understand correctly you want the flamethrower to only be active when the button is pressed.

In this case you have forgotten to turn it of (set it to inactive) with an else statement.

function Update()
{
   if (Input.GetButton("Fire1")
   {
      flameThrower.SetActive(true);
   }
   else //if the button is not pressed
   {
      flameThrower.SetActive(false);
   }
}