private void CreateParticle(Vector3?pos = null) { if (activeParticles.Count < MaximumParticles) { MyParticle p = null; float l = lifespan + Random.Range(-lifespanDeviation / 2, lifespanDeviation / 2); float si = size + Random.Range(-sizeDeviation / 2, sizeDeviation / 2); float sp = speed + Random.Range(-speedDeviation / 2, speedDeviation / 2); Vector3 d = direction + new Vector3(Random.Range(-directionDeviation.x / 2, directionDeviation.x / 2), Random.Range(-directionDeviation.y / 2, directionDeviation.y / 2), Random.Range(-directionDeviation.z / 2, directionDeviation.z / 2)); if (inactiveParticles.Count > 0) { p = inactiveParticles.Pop(); p.Reset(l, si, sp, d); p.gameObject.transform.position = (isSubEmitter && pos != null) ? (pos.Value) : (transform.position); p.gameObject.SetActive(true); } else { GameObject g = GameObject.Instantiate(particlePrefab, (isSubEmitter && pos != null) ? (pos.Value) : (transform.position), Quaternion.identity, transform); p = new MyParticle(g, l, si, sp, d); } onBirth.Invoke(p.gameObject.transform.position); activeParticles.Add(p); } }