Check out example codes for "unity key toggle". It will help you in understanding the concepts better.

Code Example 1

//This is a second simple example of a toggle using a keyboard key pressed down:
//Variables
public GameObject ON;
public GameObject OFF;
public KeyCode Interact = KeyCode.F;
private bool On_Off = false;

//you can use a void Update, a function or a IEnumerator.
public IEnumerator Toggle()
{
    if (Input.GetKeyDown(Interact))
	{
         	while (true)
         	{
             	if (On_Off == false)
             	{
                	ON.SetActive(true);
                	OFF.SetActive(false);
                	On_Off = true;
                	break;
             	}
             	if (On_Off == true)
             	{
             		ON.SetActive(false);
                	OFF.SetActive(true);
                	On_Off = false;
                	break;
             	}
         	}
	}
	if (On_Off == false)
	{
		ON.SetActive(false);
    	OFF.SetActive(true);
	}
	if (On_Off == true)
	{
		ON.SetActive(true);
    	OFF.SetActive(false);
	}
}

private void Update
{
	Toggle();
}

Code Example 2

//This is a first simple example of a toggle using a keyboard key pressed down:
//Variables
public GameObject ON;
public GameObject OFF;
public KeyCode Interact = KeyCode.F;
private bool On_Off = false;


//you can use a void Update, a function or a IEnumerator.
private void Update()
{
    if (Input.GetKeyDown(Interact))
	{
         	while (true)
         	{
             	if (On_Off == false)
             	{
                	ON.SetActive(true);
                	OFF.SetActive(false);
                	On_Off = true;
                	break;
             	}
             	if (On_Off == true)
             	{
             		ON.SetActive(false);
                	OFF.SetActive(true);
                	On_Off = false;
                	break;
             	}
         	}
	}
	if (On_Off == false)
	{
		ON.SetActive(false);
    	OFF.SetActive(true);
	}
	if (On_Off == true)
	{
		ON.SetActive(true);
    	OFF.SetActive(false);
	}
}

Learn ReactJs, React Native from akashmittal.com