Double Input.GetButton problem.

Hi guys, I’m new with Unity so don’t be too harsh on me :smiley:

I have two game objects, they are turned off at the start. With Input.GetButton(“X button”) i want to turn ON game object number one. When I use Input.GetButton(“X button”) another time I want game object number one to turn OFF, and the game object number two to turn ON. If I click again, number two gets OFF , and number one gets ON. And so on. I’m using SetActive function.

If anyone can lead me to how to go about doing this it would be greatly appreciated!

public GameObject g1;
public GameObject g2;
bool isG1On = false;

    void Update()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            if (isG1On)
            {
                g1.SetActive(false);
                g2.SetActive(true);
                isG1On = false;
            }
            else
            {
                g1.SetActive(true);
                g2.SetActive(false);
                isG1On = true;
            }
        }
    }