Unity Script debug error

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

public class yokol : MonoBehaviour
{
public Text skor;
private int a;
void Start()
{
Destroy(gameObject, 2);
}
void OnCollisionEnter2D(Collision2D collision)
{

if (collision.gameObject.name == “adam”)
{

Debug.Log(a);
Destroy(gameObject);
skor.text = a.ToString();
a++;

a++ is not work
console out is
0
0
0
0

}

You display it, then increment it.

Of course it is still zero.

Remember that each instance of yokol has its own a variable. They are NOT the same variable, so if you expect this to go ever upwards, it won’t.

If you need a single score that all instances yokol can continue to increment, here is one possible static solution:

https://gist.github.com/kurtdekker/50faa0d78cd978375b2fe465d55b282b

Please ask scripting questions on the dedicated scripting forum. Use this 2D forum to ask specific 2D questions.

Also, always use code-tags when posting code, not plain text. Please edit your post to include them, thanks.

I’ll move your post for you.