/// <summary> /// Sets the target volume and pitch of the sliding sound effect based on the given object that was hit, velocity, and normal. /// </summary> public void SetTargetVolumeAndPitch(GameObject parentObject, GameObject otherObject, Vector3 relativeVelocity, Vector3 normal, bool exit, float mod = 1) { if (SlideAudio == null) { return; } float vol = exit || !_mat.CollideWith(otherObject) ? 0 : _mat.GetSlideVolume(relativeVelocity, normal) * _baseVol * mod; if (_lastFrame == Time.frameCount) { if (_targetVolume < vol) { _targetVolume = vol; } } else { _targetVolume = vol; } if (!SlideAudio.isPlaying) { _basePitchRand = _basePitch * _mat.GetScaleModPitch(parentObject.transform.localScale) + _mat.GetRandomPitch(); SlideAudio.Play(); } SlideAudio.pitch = _basePitchRand + relativeVelocity.magnitude * _mat.SlidePitchMod; _lastFrame = Time.frameCount; }
/// <summary> /// Sets the target volume and pitch of the sliding sound effect based on the given object that was hit, velocity, and normal. /// </summary> public void SetTargetVolumeAndPitch(PhysSoundMaterial mat, Vector3 relativeVelocity, Vector3 normal, bool exit, float mod = 1) { if (SlideAudio == null) { return; } if (!SlideAudio.isPlaying) { basePitchRand = basePitch + Random.Range(-mat.PitchRandomness, mat.PitchRandomness); SlideAudio.Play(); } SlideAudio.pitch = basePitchRand + relativeVelocity.magnitude * mat.SlidePitchMod; targetVolume = exit ? 0 : mat.GetSlideVolume(relativeVelocity, normal) * baseVol * mod; }
/// <summary> /// Sets the target volume and pitch of the sliding sound effect based on the given object that was hit, velocity, and normal. /// </summary> public void SetTargetVolumeAndPitch(PhysSoundMaterial mat, Vector3 relativeVelocity, Vector3 normal, bool exit, float mod = 1) { if (SlideAudio == null) return; if (!SlideAudio.isPlaying) { basePitchRand = basePitch + Random.Range(-mat.PitchRandomness, mat.PitchRandomness); SlideAudio.Play(); } SlideAudio.pitch = basePitchRand + relativeVelocity.magnitude * mat.SlidePitchMod; targetVolume = exit ? 0 : mat.GetSlideVolume(relativeVelocity, normal) * baseVol * mod; }