How to I toggle a button on/off with a button pressed?

So I am well into a first person shooter, thanks to you guys and all your help, and I wanted to make a level where you are trying to catch a terrorist, but all the house electricity is out. The solution: a flashlight. I want to be able to toggle the flashlight on/off with the ‘f’ key, like in Half Life, Gmod, Transmissions Element 120, etc. Here is the script so far, but I do not know how to do it.

    public AudioSource flashlightOn; 
public AudioSource flashlightOff; 
    //audio sources that have the clicking noise for the flashlight
    public GameObject flashlight; 

void Start () {

void Update () {
            if (Input.GetButtonDown (KeyCode.F)) {
                         flashlight.SetActive = true;  
                         flashlightOn.Play (); 
                } else {
                            flashlight.SetActive = false;
                            flashlightOff.Play (); 



Well, SetActive is a function, not a variable. So you need to call it with parentheses.

Second, you want to toggle the flashlight. Right now your code says “if the ‘F’ key was pressed down this frame, turn on, otherwise, turn off.” What you want it to say is something like “if the ‘F’ key was pressed down this frame, switch the state to the opposite one”. So you could do something like this:

    flashlight.SetActive( ! flashlight.activeSelf );