[SOLVED] Getting NullReferenceException when using image.color = Color.clear;

So heres my code:
Code (CSharp):

  • using System.Collections;
  • using System.Collections.Generic;
  • using UnityEngine;
  • using UnityEngine.UI;
    • public class TouchController : MonoBehaviour
  • {
    • public TextMesh Check;
  • public Graphic left;
  • public Graphic right;
  • Color rc;
  • Color lc;
    • public void Start()
  • {
  • left = GetComponent();
  • right = GetComponent();
  • rc = Color.clear;
  • lc = Color.clear;
  • }
  • public void LeftClick()
  • {
  • Check.text = “left”;
  • left.color = lc;
  • right.color = rc;
  • }
  • public void RightClick()
  • {
  • Check.text = “Right”;
  • left.color = lc;
  • right.color = rc;
  • }
  • }

Everytime RightClick() or LeftClick() is run i get a NullReferenceException on the line left.color = lc; anyone know why?

p.s I have set the graphics and textmesh in the inspector.

maybe the color variable isn’t working properly (for me too but in other ways )
or Color.clear doesn’t or the variable left isnt a color variable

Sorry, forgot to say that I found the problem, needed to get rid of lines 17 and 18, and use images instead of graphics