I have a problem with my code . I was working on displaying it if certain condition is met for counting by destroying objects but I keep getting an error, but my game works even with the error but I have to press the || button. I have no idea of what I did wrong. I would love to remove the error.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DestroyScript : MonoBehaviour
{
public Text countText;
private int count;
public Text winText;
void Start()
{
count = 0;
SetCountText ();
winText.text = "";
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Pick Up"))
{
other.gameObject.SetActive(false);
count = count + 1;
SetCountText();
}
}
void SetCountText()
{
countText.text = "Count: " + count.ToString();
if(count >= 12)
{
winText.text = "You Can buy Pizza now!!!";
}
}
}
My error is :
NullReferenceException: Object reference not set to an instance of an object
DestroyScript.SetCountText () (at Assets/DestroyScript.cs:32)
DestroyScript.Start () (at Assets/DestroyScript.cs:16).
Any help would be greatful thank you