help needed score system

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class coin : MonoBehaviour
{
    public SpriteRenderer sr;
    public BoxCollider2D bc;
    public TextMesh tm;

    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.transform.gameObject.name == "player") { sr.enabled = false;bc.enabled = false; }
    }

    // Update is called once per frame
    void Update()
    {
      
    }
}

so i want to make a score system where when you touch a coin it dissapear and gives you one point but i dont know what to put in this if statment to do that

notes: im using a text mesh for this because normal text doesnt work for me

Anywhere at your code you should have a coin count:

public class AnyClass
{
    public static int coins;
}

At the if statement:

AnyClass.coins++;
Destroy(gameObject);

Just an example, but you would have more valid methods.

but how would i make it go into a text box

Through the class Text. You make a Text and attach it from inspector. You can change the value from the text like this:

public Text text;

text.text = "Whatever you want to show there";

Remember you would need “using UnityEngine.UI;”

How to implement it in a game? This is an example.
Well this is a Singleton. It allows you to call it from UIController.Instance but if you don’t understand something about how it works, don’t worry, the important thing about this is the Text vars:

public class UIController : MonoBehaviour
{
    public Text coinText, hpText, otherText;

    private static UIController instance;
    public UIController Instance
    {
        get
        {
            if (instance == null) instance = this;
            else Destroy(this);
            return instance;
        }
    }
}

You can access it from anywhere by UIController.Instance;

AnyClass.coins++;
Destroy(gameObject);
UIController.Instance.coinText.text = AnyClass.coins.ToString();