Points system in Unity not working. I want to count points but make both objects disappear and it's not working

32 Views Asked by At

I'm developing a game, but I have hit a breakpoint and I can't figure a solution for my problem. I want to make a bullet and an object, and when they collide, they both disappear and ads 1 point to a counter. I have tried a few different ways but nothing has worked. I think it's because the bullet disappears after it hits the object.

The bullet script:

private void OnCollisionEnter2D(Collision2D collision)
{
    if (collision.gameObject.tag == "Object")
    {
        points = points + 1;
        Destroy(gameObject);
    }
}

The points script:

void Update()
{
    if (bullet.points == 1)
    {
       pointcounter++;
    }
}

I made it if (bullet.points == 1) because the bullet will destroy the object after it hits so it will reset to 0 automatically (at least I think it will).

I have also tried doing it in the bullet script and not using a points script but it didn't work.

0

There are 0 best solutions below