I have a problem with coins

//I’m using this inside my gamemanager script

points.text = “Points:” + player.currentPoints.ToString();


// I’m using these inside my player script

internal int currentPoints;

internal int point = 10;

void OnTriggerEnter2D(Collider2D other)

{

if (other.tag == “Coin”)

{
        currentPoints += point;
        Destroy(other.gameObject);
}

}


I have a coin which was supposed to give me 10 points, but sometimes it gives me 10, sometimes 20 or 30. Can anyone explain what’s wrong with my code? (sorry for my english by the way)

This is happening because OnTriggerEnter is called multiple times, as there are number of collisons happen at that movement. You should use some other method for adding points or take a bool( if first collision happens it should not go for another one)