deactivate a object through c#

So in my really simple Simon Says type game, one of six colors will flash and the player repeats the pattern. However, the way the game works, you can press colors before and after the game is being played. How would I make it so the objects are disabled or so that they don’t do anything until the start game button is pressed? Thanks

using UnityEngine; 
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;

public class GameManager : MonoBehaviour {

	public SpriteRenderer[] colors;
	public AudioSource[] buttonSounds;
	private int colorSelect;
	public float lit;
	private float litCounter;
	public float waitBetweenLights;
	private float waitBetweenCounter;
	public float waitBetweenLevels;
	private float waitBetweenLevelsCounter;
	private bool shouldBeLit;
	private bool shouldBeDark;
	public List<int> activeSequence;
	private int posInSequence;
	private bool gameActive;
	private int inputInSequence;
	public AudioSource correct;
	public AudioSource incorrect;
	public Text scoreText;
	public Text startGameText;
	public Button startButton;

	// Use this for initialization
	void Start () {

		if (!PlayerPrefs.HasKey ("EasyHighScore")) {
			PlayerPrefs.SetInt ("EasyHighScore", 0);
		}

		scoreText.text = "Score: 0 - High Score: " + PlayerPrefs.GetInt ("EasyHighScore");
		
	}

	// Update is called once per frame
	void Update () {
		if (shouldBeLit) {
			litCounter -= Time.deltaTime;
			if (litCounter < 0) {
				colors [activeSequence[posInSequence]].color = new Color (colors [activeSequence[posInSequence]].color.r, colors [activeSequence[posInSequence]].color.g, colors [activeSequence[posInSequence]].color.b, 0.5f);
				buttonSounds[activeSequence[posInSequence]].Stop();
				shouldBeLit = false;
				shouldBeDark = true;
				waitBetweenCounter = waitBetweenLights;
				posInSequence++;
			}
		}

		if (shouldBeDark) {
			waitBetweenCounter -= Time.deltaTime;
			if (posInSequence >= activeSequence.Count) {
				shouldBeDark = false;
				gameActive = true;
			} else {
				if (waitBetweenCounter < 0) {
					colors [activeSequence[posInSequence]].color = new Color (colors [activeSequence[posInSequence]].color.r, colors [activeSequence[posInSequence]].color.g, colors [activeSequence[posInSequence]].color.b, 1f);
					buttonSounds[activeSequence[posInSequence]].Play();
					litCounter = lit;
					shouldBeLit = true;
					shouldBeDark = false;
				}
			}
		}

	}
		

	public void StartGame () {
		activeSequence.Clear ();
		posInSequence = 0;
		inputInSequence = 0;
		colorSelect = Random.Range (0, colors.Length);
		activeSequence.Add (colorSelect);
		colors [activeSequence[posInSequence]].color = new Color (colors [activeSequence[posInSequence]].color.r, colors [activeSequence[posInSequence]].color.g, colors [activeSequence[posInSequence]].color.b, 1f);
		buttonSounds[activeSequence[posInSequence]].Play();
		litCounter = lit;
		shouldBeLit = true;
		scoreText.text = "Score: 0 - High Score: " + PlayerPrefs.GetInt ("EasyHighScore");
		startGameText.text = "Easy";
		startButton.interactable = false;
		//Proably here the objects would be enabled
	}

	public void ColorPressed(int whichButton){

		if (activeSequence[inputInSequence] == whichButton) {
			if (gameActive) {
					Debug.Log ("Correct");
					inputInSequence++;
			}
				if (inputInSequence >= activeSequence.Count) {
					if (activeSequence.Count > PlayerPrefs.GetInt ("EasyHighScore")) {
						PlayerPrefs.SetInt ("EasyHighScore", activeSequence.Count);
					}
					scoreText.text = "Score: " + activeSequence.Count + "- High Score: " + PlayerPrefs.GetInt ("EasyHighScore");
					posInSequence = 0;
					inputInSequence = 0;
					colorSelect = Random.Range (0, colors.Length);
					activeSequence.Add (colorSelect);
					colors [activeSequence[posInSequence]].color = new Color (colors [activeSequence[posInSequence]].color.r, colors [activeSequence[posInSequence]].color.g, colors [activeSequence[posInSequence]].color.b, 1f);
					buttonSounds[activeSequence[posInSequence]].Play();
					litCounter = lit;
					shouldBeLit = true;
					gameActive = false;
					correct.Play ();
				}
				} else {
					Debug.Log ("Wrong");
					incorrect.Play ();
					gameActive = false;
					startButton.interactable = true;
				//Proably here the objects would be disabled
				}
		}

	}

Hello.

The line you are looking for is gameObject.SetActive (true/false). Replace gameObject with an object reference which you want to enable/disable. You can store objects in an array of GameObjects and loop through it to enable or disable all of them.

To activate/deactivate objects in the scene through script there is

objectToActivate.gameObject.SetActive(true);
objectToActivate.gameObject.SetActive(false);

Be aware that the GameObject has to be created first in the script to link it in Unity with:

public GameObject objectName;

Example:

using UnityEngine;
using System;

public class RedButton : MonoBehaviour {

	public GameObject button;

void OnMouseOver(){
        button.gameObject.SetActive (false);
}

void OnMouseExit(){
        button.gameObject.SetActive (true);
}
}