Beispiel #1
0
    public GameObject Take()
    {
        Particle particle;

        if (available.Count > 0)
        {
            particle = available[0];
            available.RemoveAt(0);
            particle.transform.parent = this.transform;
        }
        else if (pool.Count < maxInstance)
        {
            particle      = factory.GetParticle();// Instantiate(factory.generatedCars[Random.Range(0, factory.generatedCars.Length)]).GetComponent<Particle>();
            particle.pool = this;
            pool.Add(particle);
            lastInstanceIndex = pool.Count - 1;

            particle.transform.parent = this.transform;
        }
        else
        {
            particle          = pool[lastInstanceIndex];
            lastInstanceIndex = (lastInstanceIndex + 1) % maxInstance;
        }
        particle.ResetParticle();
        active[particle.gameObject] = particle;
        return(particle.gameObject);
    }