当前位置: 首页>>代码示例>>C#>>正文


C# AudioSource.Stop方法代码示例

本文整理汇总了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 ();
			
			//}

		}

	}
开发者ID:TeamTacoCat,项目名称:DAWG,代码行数:27,代码来源:MusicSingleton.cs

示例2: OnBossDie

 private void OnBossDie( BossDeadStateInfo.Died obj )
 {
     fxSound = GetComponent<AudioSource>();
     fxSound.Stop();
     fxSound.clip = endgameSoundtrack;
     fxSound.Play();
 }
开发者ID:OrangeeZ,项目名称:Crandell,代码行数:7,代码来源:Soundtrack.cs

示例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();
                }
            }
        }
开发者ID:paulkelly,项目名称:GGJ2016,代码行数:26,代码来源:AudioCrossFader.cs

示例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é
        }
    }
开发者ID:lpointet,项目名称:runblobby,代码行数:26,代码来源:_StaticFunction.cs

示例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();
    }
开发者ID:dshpet,项目名称:SpaceBeat,代码行数:31,代码来源:MainTestPlayer.cs

示例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 ();
		}
	}
开发者ID:kkiniaes,项目名称:Fire-On-Ice,代码行数:7,代码来源:DieWater.cs

示例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;
	}
开发者ID:rangermann,项目名称:ggj16,代码行数:27,代码来源:GameStatePlaying.cs

示例8: Start

 void Start()
 {
     source = gameObject.GetComponent<AudioSource>();
     source.Stop ();
     source.time = 100;
     source.Play ();
 }
开发者ID:jimmytheleaf,项目名称:game-jolt-10,代码行数:7,代码来源:StartSongMidway.cs

示例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();
 }
开发者ID:PatrikkSorensen,项目名称:GAMEDEV2016,代码行数:7,代码来源:MazeRisingScript.cs

示例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();
    }
开发者ID:kdoore,项目名称:unity-5-cookbook-codes,代码行数:31,代码来源:PlayVideo.cs

示例11: Start

 void Start()
 {
     source = GetComponent<AudioSource>();
     source.Stop();
     source.Play();
     source.loop = true;
 }
开发者ID:Madzzzz,项目名称:Pilot-Rep,代码行数:7,代码来源:SoundControll.cs

示例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 ();
         }
     }
 }
开发者ID:AaronEastwood,项目名称:MUC6-survival,代码行数:31,代码来源:SoundManager.cs

示例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 ();
	}
开发者ID:paleonluna,项目名称:PotF,代码行数:7,代码来源:WinCondition.cs

示例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();

        }
    }
开发者ID:cambo2015,项目名称:VirtuallyDone,代码行数:29,代码来源:Bowling.cs

示例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);
    }
开发者ID:ChielBruin,项目名称:legend-of-iris,代码行数:33,代码来源:AudioPlayer.cs


注:本文中的UnityEngine.AudioSource.Stop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。