protected virtual GameObject GetItem() { GameObject instance; do { if (items.Count > 0) { instance = items.Pop(); } else { instance = CreateItem(); } } while (instance == null); // Take in account possibility that gameobject was destroyed PoolSubject subject = instance.GetComponent <PoolSubject>(); if (subject && subject.killtime > 0f) { ReturnItem(instance, subject.killtime); } //AudioSource source = instance.GetComponent<AudioSource>(); //if (source) { source.enabled = true; source.Play(); } instance.SetActive(true); return(instance); }
public void PlayWeaponSoundAt(AudioClip clip, Vector3 position, float rps, float volume = 0.1f) { GameObject instance = GetItem(transform, position); AudioSource source = instance.GetComponent <AudioSource>(); PoolSubject subject = instance.GetComponent <PoolSubject>(); source.clip = clip; source.pitch = Mathf.Max(rps / 30, 1f); source.volume = volume / 10f; source.Play(); subject.killtime = source.clip.length / source.pitch; }