public void playInstance(AudioClip clip, int maxActive, float volume, bool startMuted = false) { if (!clip) { return; } List <SoundEffectHandler> handlerList = getHandlerList(clip, true); Assert.IsNotNull(handlerList); // Recycle an existing handler if we have already passed max amount of effects. // We grab the oldest one and use that (it later gets added to the back again) SoundEffectHandler handler = null; if (handlerList.Count >= maxActive) { handler = handlerList[0]; handlerList.RemoveAt(0); } if (!handler) { handler = spawnHandler(); } Assert.IsNotNull(handler); handlerList.Add(handler); handler.playClip(clip, volume, startMuted); }