Search Unity

Audio Implementing different sounds for Footsteps in Angry Bots Unity Project

Discussion in 'Audio & Video' started by mindairflavor, Jun 15, 2017.

  1. mindairflavor

    mindairflavor

    Joined:
    Jun 15, 2017
    Posts:
    2
    Hi,
    I've recorded some sound of footsteps and i'm trying to import these sounds into the Angry Bots Unity Project in the Unity Editor. In the FxManager I've seen that i can attach sound of footsteps.
    Through the FxManager already present within the project (In the Hierarchy View) there is the possibility to enter different sounds of footsteps depending on the material with which the player enter in collision by walking. The problem is that I have inserted different sounds for the concrete and metal surfaces, but during the playing phase only the concrete sounds are played even if the player walks on the metal surfaces.
    My impression is that the game has problems with recognizing different materials. Can anyone help me solve the problem?

    Thanks
     
  2. mindairflavor

    mindairflavor

    Joined:
    Jun 15, 2017
    Posts:
    2
    I found a script in the project where there is the function GetPlayerFootstepSound that receives a random footstep sound from an array and this function takes one of the 4 different sounds available for each surface (4 sounds of footsteps and 4 for the concrete).
    Here is the code:
    Code (csharp):
    1.  
    2.  
    3. #pragma strict
    4.  
    5. class MaterialImpact {
    6. var physicMaterial : PhysicMaterial;
    7. var playerFootstepSounds : AudioClip[];
    8. var mechFootstepSounds : AudioClip[];
    9. var spiderFootstepSounds : AudioClip[];
    10. var bulletHitSounds : AudioClip[];
    11.  
    12. }
    13.  
    14. class MaterialImpactManager extends MonoBehaviour {
    15. var materials : MaterialImpact[];
    16.  
    17. private static var dict : System.Collections.Generic.Dictionary.<PhysicMaterial, MaterialImpact>;
    18. private static var defaultMat : MaterialImpact;
    19.  
    20. function Awake () {
    21. defaultMat = materials[0];
    22. dict = new System.Collections.Generic.Dictionary.<PhysicMaterial, MaterialImpact> ();
    23. for (var i : int = 0; i < materials.Length; i++) {
    24. dict.Add (materials[i].physicMaterial, materials[i]);
    25. }
    26. }
    27.  
    28. static function GetPlayerFootstepSound (mat : PhysicMaterial) : AudioClip {
    29. var imp : MaterialImpact = GetMaterialImpact (mat);
    30. Debug.Log("Player is walking on "+imp.physicMaterial);
    31. return GetRandomSoundFromArray(imp.playerFootstepSounds);
    32.  
    33. }
    34.  
    35. static function GetMechFootstepSound (mat : PhysicMaterial) : AudioClip {
    36. var imp : MaterialImpact = GetMaterialImpact (mat);
    37. return GetRandomSoundFromArray(imp.mechFootstepSounds);
    38. }
    39.  
    40. static function GetSpiderFootstepSound (mat : PhysicMaterial) : AudioClip {
    41. var imp : MaterialImpact = GetMaterialImpact (mat);
    42. return GetRandomSoundFromArray(imp.spiderFootstepSounds);
    43.  
    44. }
    45.  
    46. static function GetBulletHitSound (mat : PhysicMaterial) : AudioClip {
    47. var imp : MaterialImpact = GetMaterialImpact (mat);
    48. return GetRandomSoundFromArray(imp.bulletHitSounds);
    49.  
    50. }
    51.  
    52. static function GetMaterialImpact (mat : PhysicMaterial) : MaterialImpact {
    53. if (mat && dict.ContainsKey (mat))
    54. return dict[mat];
    55. return defaultMat;
    56. }
    57.  
    58. static function GetRandomSoundFromArray (audioClipArray : AudioClip[]) : AudioClip {
    59. if (audioClipArray.Length > 0)
    60. return audioClipArray[Random.Range (0, audioClipArray.Length)];
    61. return null;
    62. }
    63.  
    64. }
    65.  
    66.  
    I've inserted a Debug.Log in the function to check for the material that the Player touches by walking during gameplay but the log always says that the player is walking on the Concrete material. So i think that there's a problem in recognizing the different surfaces.
    Someone could give me any suggestion please?
    Thank you