The current score variable not updating when an enemy is hit (Using OnTriggerEnter2D function),Counter for current score not working with OnTriggerEnter2D function.

I have made a script called “Ball”, attached to a sphere prefab. In this script, i have added the following lines of code -
private void OnTriggerEnter2D(Collider2D col)
{

    if (col.gameObject.tag == "Enemy")
    {
        
        curr = curr + 1;
        Debug.Log(curr);

        Destroy(col.gameObject);
        Destroy(gameObject);
    }

}

Now the thing is, the curr variable is not updating as should be. The last two destroy statements are working as usual. I have used Debug.Log to print the updated value of curr variable, but console displays something like this -

This screenshot was taken when the sphere hit the “Enemy” 4 times. Can anyone explain what is happening and how I can rectify this? I just want the console to show the current value of curr variable.

A few things come to mind:

  • Disable “Collapse” in the console to make sure the collapsed logs all say “1”
  • Check that nothing else in your script is affecting the “curr” variable.
  • Post the entire script for more detailed help.