When I run my program I keep getting: MissingComponentException: There is no 'TextMesh' attached to the "Can" game object, but a script is trying to access it.
Even though I have attached it as you can see:
In the script I am trying to edit the text of the Text Mesh like this¨:
private int count;
public TextMesh countText;
// Use this for initialization
void Start () {
count = 0;
counterText = gameObject.GetComponent<TextMesh>();
counterText.text = "Count: " + count.ToString();
}
What I want is to count the cans that have been shot, so what I do next is:
void OnCollisionEnter(Collider other)
{
if (other.gameObject.CompareTag("Can"))
{
other.gameObject.SetActive(false);
count = count + 1;
counterText.text = "Count: " + count.ToString();
}
}