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


C# AudioSource.Play方法代码示例

本文整理汇总了C#中UnityEngine.AudioSource.Play方法的典型用法代码示例。如果您正苦于以下问题:C# AudioSource.Play方法的具体用法?C# AudioSource.Play怎么用?C# AudioSource.Play使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.AudioSource的用法示例。


在下文中一共展示了AudioSource.Play方法的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: Start

    //void awake()
    //{
    //}
    IEnumerator Start()
    {
        source = GetComponent<AudioSource>();
        while (true)
        {

                // Make a bullet with the same position and rotation as the player
            float vol = Random.Range(volLowRange, volHighRange);
            if (powerUp == true)
            {
                var bulpower = Instantiate(powerup, transform.position, transform.rotation);

                source.volume = vol;
                source.Play();

                // Wait 0.2 seconds
                Destroy(bulpower, 1);
                yield return new WaitForSeconds(0.2f);
            }
            else
            {
                var bul = Instantiate(bullet, transform.position, transform.rotation);

                source.volume = vol;
                source.Play();

                // Wait 0.2 seconds
                Destroy(bul, 1);
                yield return new WaitForSeconds(0.2f);
            }

        }
    }
开发者ID:schoolsout,项目名称:Schools-Out,代码行数:36,代码来源:PlayerShoot.cs

示例3: Start

    // Use this for initialization
    void Start()
    {
        transform.localScale = new Vector3(Camera.main.orthographicSize/2 * (Screen.width/Screen.height),Camera.main.orthographicSize/2,1f);

        audioSource = GetComponent<AudioSource> ();

        if (HammerController.gameOverState == 1) {
            //success
            GetComponent<MeshRenderer> ().materials [0].mainTexture = textures [0];
            movTerxture = (MovieTexture)GetComponent<MeshRenderer> ().materials [0].mainTexture;
            movTerxture.Play();
            audioSource.clip = music1;
            audioSource.Play();
            audioSource.PlayOneShot(voiceovers[0]);

        }
        else if(HammerController.gameOverState == 2 )
        {
            GetComponent<MeshRenderer> ().materials [0].mainTexture = textures [1];
            movTerxture = (MovieTexture)GetComponent<MeshRenderer> ().materials [0].mainTexture;
            movTerxture.Play();
            audioSource.clip = music2;
            audioSource.Play();
            audioSource.PlayOneShot(voiceovers[1]);

        }
    }
开发者ID:ankit01217,项目名称:Float-Me-Up,代码行数:28,代码来源:EndController.cs

示例4: Start

    // Use this for initialization
    void Start()
    {
        aSource = GetComponent<AudioSource>();

        aSource.Play();
        aSource.clip = song1;
        aSource.Play();
    }
开发者ID:Team2point5D,项目名称:Davinas-Stone-Full,代码行数:9,代码来源:FadeInOutMusic.cs

示例5: PlayAudioSource

 public void PlayAudioSource(AudioSource audioSource)
 {
     if (AudioSources.Contains(audioSource)) {
         if (AllowClipping)
             audioSource.Play();
         else if (AudiosBeingPlayed() == 0)
             audioSource.Play();
     }
 }
开发者ID:juliancruz87,项目名称:madbricks,代码行数:9,代码来源:AudioSourceGroup.cs

示例6: playSound

 void playSound(AudioSource sound)
 {
     if (sound.isPlaying)
     {
         sound.Stop();
         sound.Play();
     }
     else
         sound.Play();
 }
开发者ID:takkasila,项目名称:spoodimal,代码行数:10,代码来源:SoundController.cs

示例7: Start

	// Use this for initialization
	void Start () {

		//Get a component reference to the Character's animator component
		animator = GetComponent<Animator>();
		render = GetComponent<SpriteRenderer>();

		//Get the rigid body on the prefab
		bullBody = GetComponent<Rigidbody2D>();

		//Set our bullet strength and speed
		strength = 4;
		speed = 40;

		//Go after our player!
		player = GameObject.Find("Player").GetComponent<Player>();

		//Get our Player current Direction
		if (player.getDirection () > 0 ||
			(player.getDirection() == 0 && player.getLastDirection() > 0 )) {
			animator.SetInteger ("Direction", 1);
			playerRight = true;
		} else {
			playerRight = false;
			animator.SetInteger ("Direction", -1);
		}

		//Play our shooting sound
		shoot = GameObject.Find ("Shoot").GetComponent<AudioSource> ();

			shoot.Play ();

		//Get our camera script
		actionCamera = Camera.main.GetComponent<ActionCamera>();
	}
开发者ID:julianpoy,项目名称:HackPoly2016,代码行数:35,代码来源:Bullets.cs

示例8: Start

 void Start()
 {
     audioSrc = GetComponentInChildren<AudioSource> ();
     audioSrc.clip = BGM_main;
     audioSrc.Play (0);
     //audioSrc.ignoreListenerVolume = true;
 }
开发者ID:StudioMimimushi,项目名称:BobTheFrog,代码行数:7,代码来源:SoundManagerScript.cs

示例9: Start

 // Use this for initialization
 void Start()
 {
     sE = gameObject.AddComponent<AudioSource>();
     sE.clip = pop [Random.Range(0, 4)];
     sE.volume = seVolume;
     sE.Play ();
 }
开发者ID:calvinatlan,项目名称:BubbleCubed,代码行数:8,代码来源:PopSound.cs

示例10: Start

 //private GameObject leftBlade;
 //private GameObject rightBlade;
 // Use this for initialization
 void Start()
 {
     //healthHandler = GameObject.Find ("PlayerHealthHandler");
     hitSoundSource = transform.FindChild ("hitSoundPlayer").gameObject.GetComponent<AudioSource> ();
     newBladeSoundSource = transform.FindChild ("newBladeSoundPlayer").gameObject.GetComponent<AudioSource> ();
     newBladeSoundSource.Play();
 }
开发者ID:owlmazing,项目名称:Hand2Hand,代码行数:10,代码来源:Blade.cs

示例11: Awake

	/// <summary>
	/// 
	/// </summary>
	void Awake()
	{

		if (SpawnObjects == null)
			return;

		int i = (int)Random.Range(0, (SpawnObjects.Count));

		if(SpawnObjects[i] == null)
			return;

		GameObject obj = (GameObject)vp_Utility.Instantiate(SpawnObjects[i], transform.position, transform.rotation);

		obj.transform.Rotate(Random.rotation.eulerAngles);
		m_Audio = audio;
		m_Audio.playOnAwake = true;
		
		// play sound
		if (Sound != null)
		{
			m_Audio.rolloffMode = AudioRolloffMode.Linear;
			m_Audio.clip = Sound;
			m_Audio.pitch = Random.Range(SoundMinPitch, SoundMaxPitch) * Time.timeScale;
			m_Audio.Play();
		}

	}
开发者ID:Barthuc,项目名称:ProjectLevelDesign,代码行数:30,代码来源:vp_RandomSpawner.cs

示例12: OnTriggerEnter

	void OnTriggerEnter(Collider other)
	{
		switch(other.transform.tag)
		{
			case TAG_POWERUP:
				audioSource = other.transform.GetComponent<AudioSource>();
				audioSource.Play();
				PowerUp powerUp = other.transform.GetComponent<PowerUp>();
				collisionManager.OnPowerUpCollision(powerUp.powerUp);
				break;
			case TAG_OBSTACLE:
				Obstacle obstacle = other.transform.GetComponent<Obstacle>();
				collisionManager.OnObstacleCollision(obstacle.obstacle);
				break;
			case TAG_MONEY:
				audioSource = other.transform.GetComponent<AudioSource>();
				audioSource.Play();
				Note note = other.transform.GetComponent<Note>();
				collisionManager.OnMoneyCollision(note.note);
				break;
			case TAG_GABEN:
				collisionManager.ShowBubble();
				break;
		}

		if(other.tag != TAG_GABEN)
			other.gameObject.SetActive(false);
	}
开发者ID:Skillath,项目名称:GGJ16,代码行数:28,代码来源:PlayerColliderController.cs

示例13: Awake

 void Awake()
 {
     audioSource = GetComponent<AudioSource>();
     audioSource.clip = MenuSoundEffect;
     audioSource.Play();
     EventManager.StartListening( EventDictionary.ON_ENTER_GAME_STATE, OnEnterGame );
 }
开发者ID:ted10401,项目名称:project-ggj2016,代码行数:7,代码来源:AudioManager.cs

示例14: PlayMusic

    public void PlayMusic(string name, bool forceRestart)
    {
        bool shouldStartNew = false;
        // If there is current music and either forcing restart or it is not the same as requested
        if (null != mCurrentMusic && (forceRestart || mCurrentMusic.name != name))
        {
            mCurrentMusic.Stop();
            Destroy(mCurrentMusic.gameObject);
            shouldStartNew = true;
        }
        // If there is no current music
        else if (null == mCurrentMusic)
        {
            shouldStartNew = true;
        }

        AudioSource musicSource = mMusicByName[name];
        // if requested music found and should start new music
        if (null != musicSource && shouldStartNew)
        {
            mCurrentMusic = Instantiate(musicSource) as AudioSource;
            DontDestroyOnLoad(mCurrentMusic);
            mCurrentMusic.name = musicSource.name;
            if (isMusicEnabled)
            {
                mCurrentMusic.Play();
            }
        }
        // If should start new but source was null
        else if (shouldStartNew)
        {
            Debug.LogError(new System.Text.StringBuilder("Could not find music source with name: ").Append(name).ToString());
        }
    }
开发者ID:ruffenman,项目名称:CosmicCorral,代码行数:34,代码来源:SoundManager.cs

示例15: Awake

    void Awake()
    {
        if (created == false)
        {
            DontDestroyOnLoad(this.gameObject);
            myAudioSource = GetComponent<AudioSource>();
            myAudioSource.clip = myaudioclip[0];//default background music
            myAudioSource.Play();
            created = true;
        }
        else
        {
            Debug.Log("here 0");
            myAudioSource = GetComponent<AudioSource>();
            // this.gameObject.GetComponent<backgroundMusic>().enabled = false;
            Destroy(this.gameObject);//duplicate
        }

        if (PlayerPrefs.HasKey("Power Level fire") == false)
        {
            PlayerPrefs.SetInt("Power Level fire", 1);
        }
        if (PlayerPrefs.HasKey("Power Level ice") == false)
        {
            PlayerPrefs.SetInt("Power Level ice", 1);
        }
        if (PlayerPrefs.HasKey("Power Level light") == false)
        {
            PlayerPrefs.SetInt("Power Level light", 1);
        }
        if(PlayerPrefs.HasKey("Difficulty") == false)
        {
            PlayerPrefs.SetInt("Difficulty", 1);//default is easy
        }
    }
开发者ID:wolong91,项目名称:MageDuel,代码行数:35,代码来源:backgroundMusic.cs


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