/** * <summary>Plays an AudioClip on the default Sound prefab.</summary> * <param name = "audioClip">The AudioClip to play</param> * <param name = "doLoop">If True, the sound will loop</param> */ public void PlayDefaultSound(AudioClip audioClip, bool doLoop) { if (audioClip == null) { return; } if (defaultSound == null) { ACDebug.Log("Cannot play audio '" + audioClip.name + "' since no Default Sound is defined in the scene - please assign one in the Scene Manager.", audioClip); return; } if (KickStarter.stateHandler.IsPaused() && !defaultSound.playWhilePaused) { ACDebug.LogWarning("Cannot play audio '" + audioClip.name + "' on Sound '" + defaultSound.gameObject.name + "' while the game is paused - check 'Play while game paused?' on the Sound component's Inspector.", defaultSound); } if (defaultAudioSource == null) { defaultAudioSource = defaultSound.GetComponent <AudioSource> (); } if (doLoop) { defaultAudioSource.clip = audioClip; defaultSound.Play(doLoop); } else { defaultSound.SetMaxVolume(); defaultAudioSource.PlayOneShot(audioClip); } }
/** * <summary>Gets, and creates if necessary, an AudioSource used for Narration speech. If the narratorSound variable is empty, one will be generated and its AudioSource referenced.</summary> * <returns>The AudioSource for Narration speech</returns> */ public AudioSource GetNarratorAudioSource() { if (narratorAudioSource == null) { if (narratorSound != null) { narratorAudioSource = narratorSound.GetComponent <AudioSource>(); } else { GameObject narratorSoundOb = new GameObject("Narrator"); UnityVersionHandler.PutInFolder(narratorSoundOb, "_Sounds"); narratorAudioSource = narratorSoundOb.AddComponent <AudioSource>(); AdvGame.AssignMixerGroup(narratorAudioSource, SoundType.Speech); narratorAudioSource.spatialBlend = 0f; narratorSound = narratorSoundOb.AddComponent <Sound>(); narratorSound.soundType = SoundType.Speech; } } narratorSound.SetMaxVolume(); return(narratorAudioSource); }
override public float Run() { if (soundObject) { soundObject.relativeVolume = newRelativeVolume; soundObject.SetMaxVolume(); } return(0f); }
/** * <summary>Gets, and creates if necessary, an AudioSource used for Narration speech.</summary> * <returns>The AudioSource for Narration speech</returns> */ public AudioSource GetNarratorAudioSource() { if (narratorAudioSource == null) { GameObject narratorSoundOb = new GameObject("Narrator"); UnityVersionHandler.PutInFolder(narratorSoundOb, "_Sounds"); narratorAudioSource = narratorSoundOb.AddComponent <AudioSource>(); AdvGame.AssignMixerGroup(narratorAudioSource, SoundType.Speech); #if UNITY_5 || UNITY_2017_1_OR_NEWER narratorAudioSource.spatialBlend = 0f; #endif Sound narratorSound = narratorSoundOb.AddComponent <Sound>(); narratorSound.soundType = SoundType.Speech; narratorSound.SetMaxVolume(); } return(narratorAudioSource); }
protected void PlayMoveSound(float speed, float trackValue) { if (speed > slideSoundThreshold) { moveSound.relativeVolume = (speed - slideSoundThreshold); // * 5f; moveSound.SetMaxVolume(); if (slidePitchFactor > 0f) { moveSound.GetComponent <AudioSource>().pitch = Mathf.Lerp(GetComponent <AudioSource>().pitch, Mathf.Min(1f, speed), Time.deltaTime * 5f); } } if (speed > slideSoundThreshold && !moveSound.IsPlaying()) // && trackValue > 0.02f && trackValue < 0.98f) { moveSound.relativeVolume = (speed - slideSoundThreshold); // * 5f; moveSound.Play(moveSoundClip, true); } else if (speed <= slideSoundThreshold && moveSound.IsPlaying() && !moveSound.IsFading()) { moveSound.FadeOut(0.2f); } }