How do you make a door toggle?

I am a beginner at C# so I apologize in advance for any stupid questions

But anyway, I tried to make a door toggle in unity; just a simple one with no animations, but for some reason it will not toggle on and off, here is the code:

public class DoorOpen : MonoBehaviour
{


public GameObject Door;



void Update()
{


if (Input.GetKeyDown(KeyCode.Space))
        {
   
            Door.SetActive(false);

        }

        if (Door.SetActive = false)
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                Door.SetActive(true);
            }
        }


    }

}
if (Input.GetKeyDown(KeyCode.Space))
{
  Door.SetActive(!Door.activeSelf);
}

Where do you put that on the script?

void Update()
{
if (Input.GetKeyDown(KeyCode.Space)) Door.SetActive(!Door.activeSelf);
}

Thanks! I’ll put it straight to use!

1 Like