Trying to use the amount of particles as score

Hello,

At the moment I’m working on a game with the goal to destroy objects.
When an object is destroyed a particle system is a particlesystem is initiated.
I then add up the amount of particles and that should be the score.
This is de code I use:

    void VindVlekken()
    {
        float score = 0;
        vlekken = GameObject.FindGameObjectsWithTag("splash"); //Vult een array met objecten met de tag splash

        for (int i = 0; i < vlekken.Length; i++)
        {
            ParticleSystem splash = vlekken[i].GetComponent<ParticleSystem>();
            int aantalSplash = splash.particleCount; //De particles onstaan pas een paar frames na de start dus de eerste partcleCounts geven 0

            score += aantalSplash;
        }
       
        Debug.Log(score);
    }

The problem is that when particles disapear (are killed) the amount of particles doesn’t change.
This method is called in the update() so I would expect the amount to be updated…
Is there a way to really count the particles in a scene?

I must say that I’m really new to programming and such, so I apologize if I’m slow of understanding

Sounds good so far!

No, don’t do that. Scoring is a separate function from particle display. Add to the score at the same time you trigger the particle system, perhaps, but don’t attempt to actually use the particle systems to keep your score.

1 Like

I’ll try that! I was kind of fixated on the whole particle sytem problem… I’m thinking of adding the amount of particles of a particle system to the score. That way I can have different particle systems with different amounts of particles. Maybe I can use a trigger to send a message when a particle is killed…

Thanks!

I solved it by letting the particles send a message when they collide with the ‘monster’ and are destroyed. The monster adds 1 to an int for each particle it collides with.

So then I have the total amount of particles created and the amount of particles destroyed. If I subtract one of the other I have the live amount of particles (I think).