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.