/// <summary> /// Play step sound /// </summary> /// <param name="material"></param> public virtual IEnumerator PlayLandSound() { RaycastHit landHit; playLandSoundCoroutineIsRunning = true; if (Physics.Raycast(characterMotor.CharacterTransform.position, -Vector3.up, out landHit, 100.0f)) { Object surfaceInfo = SurfaceHelper.GetSurfaceType(landHit.collider, landHit.point); if (!surfaceInfo) { playLandSoundCoroutineIsRunning = false; yield break; } for (int i = 0; i < footstepsMaterials.Length; i++) { if (footstepsMaterials[i].physicMaterial == surfaceInfo || footstepsMaterials[i].texture == surfaceInfo) { int randomClip = Random.Range(0, footstepsMaterials[i].landingClips.Length); audioSource.PlayOneShot(footstepsMaterials[i].landingClips[randomClip]); playLandSoundCoroutineIsRunning = false; yield break; } yield return(null); } } playLandSoundCoroutineIsRunning = false; yield break; }
/// <summary> /// Handling character steps /// </summary> protected virtual void ProcessingSteps() { RaycastHit leftFootRayHit; if (Physics.Raycast(leftFoot.position, -leftFoot.up, out leftFootRayHit, rayRange)) { if (!leftFootIsPlayed) { Object surfaceInfo = SurfaceHelper.GetSurfaceType(leftFootRayHit.collider, leftFootRayHit.point); if (!surfaceInfo) { return; } PlayStepSound(surfaceInfo); } leftFootIsPlayed = true; } else { leftFootIsPlayed = false; } RaycastHit rigthFootRayHit; if (Physics.Raycast(rightFoot.position, -rightFoot.up, out rigthFootRayHit, rayRange)) { if (!rightFootIsPlayed) { Object surfaceInfo = SurfaceHelper.GetSurfaceType(rigthFootRayHit.collider, rigthFootRayHit.point); if (!surfaceInfo) { return; } PlayStepSound(surfaceInfo); } rightFootIsPlayed = true; } else { rightFootIsPlayed = false; } }