NullReferenceException - Object not set to an instance

Hi All,

I’m having some trouble generating a new instance of an object. The code worked fine on Start but when called up in an Update function seems to go awry. I’m only new to c# and Unity so am using this project to learn, would appreciate anyone’s insight into why this might be happening.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Mask : MonoBehaviour 
{
	public GameObject sphere;
	public GameObject selector;
	public bool isSelected = false;
	string[] maskMats = {"BLUE","GREEN","ORANGE","PURPLE","RED","YELLOW"};
	public string color="";
	public List<Mask> Neighbors = new List<Mask> ();
	public bool isMatched = false;

	void Start () 
	{
		CreateMask ();
	}
	

	public void CreateMask()
	{
		color = maskMats[Random.Range(0, maskMats.Length)];
		SpriteRenderer spriteRenderer = sphere.AddComponent<SpriteRenderer> ();
		spriteRenderer.sprite = Resources.Load<UnityEngine.Sprite> ("Materials/" + color);
		isMatched = false;
	}

The update function below is in another script:

void Update () 
    	{
    		if (isMatched) 
    		{
    			for(int i=0;i<masks.Count;i++)
    			{
    				if(masks*.isMatched)*
  •  		{*
    

_ masks*.CreateMask();_
_ masks.transform.position=new Vector3(
masks.transform.position.x,
masks.transform.position.y + 6,
masks.transform.position.z);
}
}*_

* isMatched = false;*
* }*

“The update function below is in another script:”

er…