void TriggerSound(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (_random == null) { _random = new vFisherYatesRandom(); } isTrigger = true; GameObject audioObject = null; if (audioSource != null) { audioObject = Instantiate(audioSource.gameObject, animator.transform.position, Quaternion.identity) as GameObject; } else { audioObject = new GameObject("audioObject"); audioObject.transform.position = animator.transform.position; } if (audioObject != null) { var source = audioObject.gameObject.GetComponent <AudioSource>(); var clip = sounds[_random.Next(sounds.Count)]; source.PlayOneShot(clip); } }
public void PlayRandomClip(FootStepObject footStepObject) { // if there are no clips to play return. if (audioClips == null || audioClips.Count == 0) { return; } // initialize variable if not already started if (randomSource == null) { randomSource = new vFisherYatesRandom(); } // find a random clip and play it. GameObject audioObject = null; if (audioSource != null) { audioObject = Instantiate(audioSource.gameObject, footStepObject.sender.position, Quaternion.identity) as GameObject; } else { audioObject = new GameObject("audioObject"); audioObject.transform.position = footStepObject.sender.position; } var source = audioObject.AddComponent <vAudioSurfaceControl>(); if (audioMixerGroup != null) { source.outputAudioMixerGroup = audioMixerGroup; } int index = randomSource.Next(audioClips.Count); if (particleObject && footStepObject.ground && stepLayer.ContainsLayer(footStepObject.ground.gameObject.layer)) { Instantiate(particleObject, footStepObject.sender.position, footStepObject.sender.rotation); } if (useStepMark) { StepMark(footStepObject); } source.PlayOneShot(audioClips[index]); }
public void PlayRandomClip(FootStepObject footStepObject) { // If there are no clips to play return. if (audioClips == null || audioClips.Count == 0) { return; } // initialize variable if not already started if (randomSource == null) { randomSource = new vFisherYatesRandom(); } // Find a random clip and play it. GameObject audioObject = null; if (audioSource != null) { audioObject = Instantiate(audioSource.gameObject, footStepObject.sender.position, Quaternion.identity) as GameObject; } else { audioObject = new GameObject("audioObject"); audioObject.transform.position = footStepObject.sender.position; } var source = audioObject.AddComponent <vAudioSurfaceControl>(); if (audioMixerGroup != null) { source.outputAudioMixerGroup = audioMixerGroup; } int index = randomSource.Next(audioClips.Count); if (particleObject) { var particle = Instantiate(particleObject, footStepObject.sender.position, footStepObject.sender.rotation) as GameObject; particle.SendMessage("StepMark", footStepObject, SendMessageOptions.DontRequireReceiver); } source.PlayOneShot(audioClips[index]); }