Mechanim State Sounds

Mechanim State Sounds is a script that allows you to play a Sound Group whenever a Mechanim state is entered, exited or when a certain percentage of its animation is completed. While Event Sounds can do the state entered part, the code is not event-driven, so less efficient although Event Sounds can do a lot more than just play Sound Groups. To add it, click the "Add Behavior" button on the Inspector pane after you click on a Mechanim state from the Animator window, find "Mechanim State Sounds" and add it.

 

 
The following controls appear in this script:
     
  1. Select For Sounds To Follow Object
    •  
    • Sound Follows Object: Check this to make the sound follow the game object. Otherwise it will use the initial position only.
     
  2. Retrigger Sounds Each Time Anim Loops w/o Exiting State
    •  
    • Retrigger When State Loops: Check this box if you want the timed animation sections to repeat playing their sounds every time the animation loops without exiting the animation state. If you had this checked, you could play a Sound Group timed to play when 29% of the animation was complete, all 3 times the animation looped instead of only the first time.
     
  3. Select For Sounds To Be Heard By All Connected Players
    •  
    • Multiplayer Broadcast: This checkbox only appears if you have enabled Multiplayer Capability on the Welcome Window and will make sure that all players in your multiplayer game hear the sounds you configure here. For more detail, consult the Master Audio Multiplayer page.
     
  4. Enter Sound Group
    •  
    • Play Enter Sound: Check this to play a sound when the state is entered.
    •  
    • Stop Enter Sound On Exit: Check this if you wish the Enter Sound to be stopped when the state is exited.
    •  
    • Enter Sound Group: Select a Sound Group to play for when the state is entered.
    •  
    • Enter Variation Name: You may specify a specific Variation by name from the chosen Sound Group. If you enter nothing here, a random Variation will be played.
     
  5. Exit Sound Group
    •  
    • Play Exit Sound: Check this to play a sound when the state is exited.
    •  
    • Exit Sound Group: Select a Sound Group to play for when the state is exited.
     
  6. Play Sound Group Timed To Animation
    •  
    • Play Anim Time Sound: Check this to play a sound when a certain percentage of the animation is completed.
    •  
    • Stop Anim Time Sound On Exit: Check this if you wish the Timed Sound to be stopped when the state is exited.
    •  
    • Use Stop Time: Check this if you wish the Timed Sound to be stopped at a certain completion percentage (there is another field below for this percentage).
    •  
    • When To Start Sound: Here you specify the percentage of the animation that must be complete for the sound to start. Value is between 0 and 1, with .5 meaning 50%.
    •  
    • When To Stop Sound: Here you specify the percentage of the animation that must be complete for the sound to be stopped, only if Use Stop Time is checked above. Value is between 0 and 1, with .5 meaning 50%.
    •  
    • Timed Sound Group: Select a Sound Group to play at the point that X% of the animation is completed.
    •  
    • Timed Variation Name: You may specify a specific Variation by name from the chosen Sound Group. If you enter nothing here, a random Variation will be played.
     
  7. Play Multiple Sounds Timed To Anim
    •  
    • Play Multi Anim Time Sounds: Check this to play a sound when a multiple different percentages of the animation are completed (up to 4).
    •  
    • Stop Multi Anim Time Sounds On Exit: Check this if you wish the Multi Timed Sounds to be stopped when the state is exited.
    •  
    • Num Of Multi Sounds To Play: Specify where to use 0-4 of the "When To Start" percentages below.
    •  
    • When To Start Multi Sound 1: Here you specify the percentage of the animation that must be complete for the sound to start. Value is between 0 and 1, with .5 meaning 50%.
    •  
    • When To Start Multi Sound 2: Here you specify the percentage of the animation that must be complete for the sound to start. Value is between 0 and 1, with .5 meaning 50%.
    •  
    • When To Start Multi Sound 3: Here you specify the percentage of the animation that must be complete for the sound to start. Value is between 0 and 1, with .5 meaning 50%.
    •  
    • When To Start Multi Sound 4: Here you specify the percentage of the animation that must be complete for the sound to start. Value is between 0 and 1, with .5 meaning 50%.
    •  
    • Multi Timed Sound Group: Select a Sound Group to play at the point that X% of the animation is completed.
    •  
    • Multi Timed Variation Name: You may specify a specific Variation by name from the chosen Sound Group. If you enter nothing here, a random Variation will be played.