private void playImpactSound(PhysSoundBase otherObject, Vector3 relativeVelocity, Vector3 normal, Vector3 contactPoint) { if (ImpactAudio) { AudioClip a = SoundMaterial.GetImpactAudio(otherObject, relativeVelocity, normal, contactPoint); if (a) { float pitch = baseImpactPitch + Random.Range(-SoundMaterial.PitchRandomness, SoundMaterial.PitchRandomness); float vol = baseImpactVol * SoundMaterial.GetImpactVolume(relativeVelocity, normal); ImpactAudio.pitch = pitch; if (SoundMaterial.ScaleImpactVolume) { ImpactAudio.volume = vol; } ImpactAudio.clip = a; ImpactAudio.Play(); } } }
protected void playImpactSound(GameObject otherObject, Vector3 relativeVelocity, Vector3 normal, Vector3 contactPoint) { if (SoundMaterial == null || !this.enabled || SoundMaterial.AudioSets.Count == 0 || Time.frameCount == _lastFrame) { return; } if (ImpactAudio) { AudioClip a = SoundMaterial.GetImpactAudio(otherObject, relativeVelocity, normal, contactPoint); if (a) { float pitch = baseImpactPitch * SoundMaterial.GetScaleModPitch(transform.localScale) + SoundMaterial.GetRandomPitch(); float vol = baseImpactVol * SoundMaterial.GetScaleModVolume(transform.localScale) * SoundMaterial.GetImpactVolume(relativeVelocity, normal); if (PlayClipAtPoint) { PhysSoundTempAudioPool.Instance.PlayClip(a, transform.position, ImpactAudio, SoundMaterial.ScaleImpactVolume ? vol : ImpactAudio.volume, pitch); } else { ImpactAudio.pitch = pitch; if (SoundMaterial.ScaleImpactVolume) { ImpactAudio.volume = vol; } ImpactAudio.clip = a; ImpactAudio.Play(); } _lastFrame = Time.frameCount; } } }