Activate and Deactivate gameobject on keypress

Hi i need to Activate and deactivate gameobject but i dont know how when i make script its only deactivate somebody can help me with i want on keypress F activate and then i want on keypress f too but deactivate

Thats my script :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour
{
void Update () {

if (Input.GetKeyDown(“f”))
{
gameObject.SetActive(false);
}

}
}

You can set the active on the gameObject to the opposite of what it is.

if (Input.GetKeyDown("f")) { gameObject.SetActive(!gameObject.activeSelf); }

This way it will be set to false if the object is active, and it will be set to true if the gameObject is not active.

If you do this is update it will probably not work though. I don’t think update is called on scripts if the gameobjects has it’s active set to false.