textMesh.text = "" + itemCount;
public int itemCount = 0;
public TextMeshProUGUI textMesh;
void Start()
{
textMesh = GetComponent<TextMeshProUGUI>();
UpdateText();
}
void UpdateText()
{
textMesh.text = "" + itemCount;
}
public void CollectItem()
{
itemCount++;
UpdateText();
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Player"))
{
CollectItem();
}
}