本文整理汇总了C#中UnityEngine.AudioSource.Stop方法的典型用法代码示例。如果您正苦于以下问题:C# AudioSource.Stop方法的具体用法?C# AudioSource.Stop怎么用?C# AudioSource.Stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.AudioSource
的用法示例。
在下文中一共展示了AudioSource.Stop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnLevelWasLoaded
void OnLevelWasLoaded(){
source = GetComponent<AudioSource> ();
if (GameManager.curScene == "MainMenu") {
if (source.isPlaying ) {
source.Stop ();
}
source.clip = songs [0];
source.Play ();
}else if(GameManager.curScene == "LevelLayout" || GameManager.curScene == "SinglePlayerLevel"){
//if (source.clip != songs [1]) {
source.Stop ();
source.clip = songs [Random.Range(1, 3)];
source.Play ();
//}
}
}
示例2: OnBossDie
private void OnBossDie( BossDeadStateInfo.Died obj )
{
fxSound = GetComponent<AudioSource>();
fxSound.Stop();
fxSound.clip = endgameSoundtrack;
fxSound.Play();
}
示例3: FadeAudio
public static IEnumerator FadeAudio(AudioSource source, float targetVolume, float fadeTime)
{
if (source != null)
{
float time = 0;
float startVolume = source.volume;
float percComplete = 0;
while (time < fadeTime)
{
time += Mathf.Min(1/30f, Time.unscaledDeltaTime);
percComplete = time / fadeTime;
source.volume = Mathf.Lerp(startVolume, targetVolume, percComplete);
yield return null;
}
source.volume = targetVolume;
if (targetVolume == 0)
{
source.Stop();
}
}
}
示例4: AudioFadeOut
// Fonction utilisée pour diminuer le volume d'un son progressivement
public static IEnumerator AudioFadeOut(AudioSource audio, float volumeMin = 0, float delay = 1)
{
if (audio == null || volumeMin > 1)
yield break;
if (volumeMin < 0)
volumeMin = 0;
if (delay == 0) {
audio.volume = volumeMin;
yield break;
}
while (audio.volume > volumeMin) {
audio.volume -= TimeManager.deltaTime / delay;
yield return null;
}
if (audio.volume < volumeMin) // On s'assure de ne pas aller plus bas que le volumeMin demandé
audio.volume = volumeMin;
if (audio.isPlaying) {
audio.Stop (); // On stoppe le son lorsqu'on est au min demandé
}
}
示例5: Awake
//
// Functions
//
// Use this for initialization
void Awake()
{
lastTime = 0;
audio = GetComponent<AudioSource>();
audio.Stop();
analyzer = new MusicAnalyzer(
audio.clip,
sampleSize,
soundFeed,
beatSubbands,
beatSensitivity,
thresholdSize,
thresholdMultiplier
);
while (!analyzer.Analyze())
; // make fancy rotation animation
// debug
var beats = analyzer.Beats;
var detectedBeats = analyzer.m_soundParser.DetectedBeats;
var thresholds = analyzer.Thresholds;
audio.Play();
}
示例6: PlayRandomAudio
void PlayRandomAudio(AudioClip[] clips, AudioSource audioS){
if(!audioS.isPlaying && gm.playerList.Count > 2){
audioS.Stop ();
audioS.clip = clips [Random.Range (0, clips.Length-1)];
audioS.Play ();
}
}
示例7: OnEnter
protected override void OnEnter (object onEnterParams = null)
{
//GameController.Instance.StartCoroutine (playEngineSound (0));
audio = GameObject.Find ("background_music").GetComponent<AudioSource> ();
audio.Stop ();
audio.loop = false;
part = 0;
// reset camera
TransformLevelCamera = GameController.Instance.TransformLevelCamera;
GameController.Instance.ResetCamera ();
// spawn player
SpawnPlayer ();
// start level generation
int seed = 1337; // TODO: use seed from onEnterParams
GameController.Instance.LevelGenerator.CleanUp ();
GameController.Instance.LevelGenerator.StartGenerating (seed);
GameController.Instance.Background.Reset ();
GameController.Instance.Background.Start ();
GameController.Instance.RoundStartTime = Time.time;
GameController.Instance.CurrentlyPlaying = true;
}
示例8: Start
void Start()
{
source = gameObject.GetComponent<AudioSource>();
source.Stop ();
source.time = 100;
source.Play ();
}
示例9: StopSound
IEnumerator StopSound(float time2wait, AudioSource rumble, float fadeTime)
{
yield return new WaitForSeconds(time2wait);
rumble.DOFade(0, fadeTime).SetEase(soundCurve);
yield return new WaitForSeconds(fadeTime);
rumble.Stop();
}
示例10: Start
/* ----------------------------------------
* At Start, set up movie texture and audio clip,
* playing the video if required.
*/
void Start()
{
// Assign AudioSource component to 'audio' variable
audio = GetComponent<AudioSource> ();
if (!video)
// IF there is no Movie Texure assigned to 'video', THEN use the Movie Texture assigned to the material's main texture
video = GetComponent<Renderer>().material.mainTexture as MovieTexture;
if (!audioClip)
// IF there is no Audio Clip assigned to 'audioClip', THEN use the audio clip assigned to object's Audio Source component
audioClip = audio.clip;
video.Stop ();
audio.Stop ();
// Assign 'loop' boolean value to Movie Texture's 'Loop' option
video.loop = loop;
// Assign 'loop' boolean value to Audio Source 'Loop' option
audio.loop = loop;
if(playFromStart)
// IF 'playFromStart' is selected, THEN call ControlMovie function
ControlMovie();
}
示例11: Start
void Start()
{
source = GetComponent<AudioSource>();
source.Stop();
source.Play();
source.loop = true;
}
示例12: Stop
//Created this so I could manually stop playback to avoid having two music or ambiance clips playing at once. I assume the singleton was supposed to prevent that from happening, but since I was having a problem with lines 20 through 22, I used this as a workaround.
public void Stop(string audioItem)
{
if (audioItem == "sfx") //This stops playback of the audio clip attatched to all game objects with the "SoundEffect" tag
{
GameObject[] existingSfx = GameObject.FindGameObjectsWithTag ("SoundEffect");
foreach (GameObject sfxObject in existingSfx)
{
source = sfxObject.GetComponent<AudioSource> ();
source.Stop ();
}
}
if (audioItem == "ambiance") //This stops playback of the audio clip attatched to all game objects with the "Ambiance" tag
{
GameObject[] existingAmbiance = GameObject.FindGameObjectsWithTag ("Ambiance");
foreach (GameObject ambianceObject in existingAmbiance)
{
source = ambianceObject.GetComponent<AudioSource> ();
source.Stop ();
}
}
if (audioItem == "music") //This stops playback of the audio clip attatched to all game objects with the "Music" tag
{
GameObject[] existingMusic = GameObject.FindGameObjectsWithTag ("Music");
foreach (GameObject musicObject in existingMusic)
{
source = musicObject.GetComponent<AudioSource> ();
source.Stop ();
}
}
}
示例13: FadeOutAudioSource
IEnumerator FadeOutAudioSource(AudioSource x) { //call from elsewhere
while (x.volume > 0.0f) { //where x is sound track file
x.volume -= 0.1f;
yield return new WaitForSeconds(0.3f);
}
x.Stop ();
}
示例14: sfx
void sfx(bool coolBool,bool baddieHit)
{
AudioSource[] aSources = GetComponents <AudioSource>();//fix get array out of range[??]
sound_Ball_roll = aSources[0];
//knockedOver = aSources [1];
Debug.Log ("length = " + aSources.Length);
if(coolBool == true){
sound_Ball_roll.Play();
Debug.Log ("play sfx");
}
if( coolBool == false) {
sound_Ball_roll.Stop();
Debug.Log("stopped sfx");
}
if(baddieHit == true){
//knockedOver.Play();
Debug.Log ("knocked over played");
}
if(baddieHit == false){
//knockedOver.Stop();
}
}
示例15: AudioPlayer
public AudioPlayer(AudioObject audio)
{
if (audio == null || audio.parent == null)
{
removable = true;
return;
}
this.finished = false;
this.removable = false;
this.paused = false;
this.audio = audio;
// create audio source with clip
audioGO = (GameObject)GameObject.Instantiate(AudioManager.instance.audioSourcePrefab);
//Debug.Log(audio.parent);
audioGO.transform.parent = audio.parent.transform;
audioGO.transform.localPosition = Vector3.zero;
SoundSystemManager.HandleAudioSource(audioGO);
audioAS = audioGO.GetComponent<AudioSource>();
audioAS.Stop();
audioAS.clip = audio.clip;
audioAS.volume = audio.volume;
audioAS.loop = audio.loop;
if (audio.maxDistance.HasValue)
audioAS.maxDistance = audio.maxDistance.Value;
if (audio.minDistance.HasValue)
audioAS.minDistance = audio.minDistance.Value;
playAtTime = Time.time + audio.delay;
audioAS.PlayDelayed(audio.delay);
}