Unity 3D Game Kit – footsteps

utworzone przez | Fmod, Unity

1. class PlayerController:

  public class PlayerController : MonoBehaviour, IMessageReceiver
  {

      private PlayerFmod playerFmod;
............
      void Awake()
     {
     playerFmod= GetComponent<PlayerFmod>();
..............
 void PlayAudio()
 {
     float footfallCurve = m_Animator.GetFloat(m_HashFootFall);

     if (footfallCurve > 0.01f && !footstepPlayer.playing && footstepPlayer.canPlay)
     {
         footstepPlayer.playing = true;
         footstepPlayer.canPlay = false;
         footstepPlayer.PlayRandomClip(m_CurrentWalkingSurface, m_ForwardSpeed < 4 ? 0 : 1);

         playerFmod.footstepPlay(footstepPlayer.soundbankName);

2. class RandomAudioPlayer:

  public class RandomAudioPlayer : MonoBehaviour
  {
      ......

      public String soundbankName = "";
    .......
 AudioClip InternalPlayRandomClip(Material overrideMaterial, int bankId)
 {
     ...........

     if (String.IsNullOrEmpty(bank.name))
     {
         soundbankName = "Puddle Run";//chwilowa nazwa dla defaultowego banku
     }
      else
     {
         soundbankName = bank.name;
     }

3. class playerFmod

 public class PlayerFmod : MonoBehaviour
{

    FMOD.Studio.EventInstance footsteps; // instancja dla footsteps


    void Start()
    {
         footsteps = FMODUnity.RuntimeManager.CreateInstance("event:/Ellen/Locomotion/footsteps"); // 
         FMODUnity.RuntimeManager.AttachInstanceToGameObject(footsteps, gameObject.transform);

    }

    public void footstepPlay(string  materials)
    {
       
        footsteps.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject.transform));
        footsteps.setParameterByNameWithLabel("Material", materials);
        footsteps.start();
  
    }


    private void OnDestroy()
    {
        footsteps.release();
    }

}