Score does not increment on collision(Maybe because its a prefab?)

Hello guys .So I have a prefab spawn at random locations in the screen and when the player collides with it it gets destroyed.Works great. I added a score so when the collision happens it gets incremented by 1.
I made a debug.log on the console to see if the score works great but it gets incremented to 1 .Does not get higher than that. It detects every collision and destroyed the object but every time the console outputs 1.

Is this problem caused because the object is a prefab and is the same thing?

You haven’t posted your script/code for anyone to find the problem. But still, this should work.

public class Yourscript : MonoBehaviour
{
     public int score;
    void OnCollisionEnter2D()
   {
      score++;
      Debug.log(score);
   }

It doesn’t have anything to do with prefabs. You need a global variable for score, not a variable local to every object. As it seems now, every game object has it’s own score, which you do increment, but then you kill the object, so each local score never goes beyond 1.

So somewhere you need to have a “Game Controller” script that contains the score for the whole game, and you need to give each object a way to reference that score variable. That way, when you increment the score when an object is killed, it adds to the game score.