當前位置: 首頁>>代碼示例>>C#>>正文


C# AudioSource.PlayOneShot方法代碼示例

本文整理匯總了C#中UnityEngine.AudioSource.PlayOneShot方法的典型用法代碼示例。如果您正苦於以下問題:C# AudioSource.PlayOneShot方法的具體用法?C# AudioSource.PlayOneShot怎麽用?C# AudioSource.PlayOneShot使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在UnityEngine.AudioSource的用法示例。


在下文中一共展示了AudioSource.PlayOneShot方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: 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

示例2: PlayJumpingSound

        // PlayJumpingSound
        internal void PlayJumpingSound( string groundTag, ref AudioSource m_Audio, float volumeScale )
        {
            m_Audio.pitch = Time.timeScale;
            switch( groundTag )
            {
                case TagsManager.matConcrete:
                    m_Audio.PlayOneShot( matConcrete.jumpingSound, volumeScale );
                    break;

                case TagsManager.matGravel:
                    m_Audio.PlayOneShot( matGravel.jumpingSound, volumeScale );
                    break;

                case TagsManager.matMetal:
                    m_Audio.PlayOneShot( matMetal.jumpingSound, volumeScale );
                    break;

                case TagsManager.matWood:
                    m_Audio.PlayOneShot( matWood.jumpingSound, volumeScale );
                    break;

                default:
                    m_Audio.PlayOneShot( genericMat.jumpingSound, volumeScale );
                    break;
            }
        }
開發者ID:mandarinx,項目名稱:buildahouse,代碼行數:27,代碼來源:FootStepSoundsManager.cs

示例3: OnEnter

		public override void OnEnter()
		{
			var go = Fsm.GetOwnerDefaultTarget(gameObject);
			if (go != null)
			{
				// cache the AudioSource component
				
				audio = go.audio;
				if (audio != null)
				{
					if (oneShotClip == null)
					{
						audio.Play();
						
						if (!volume.IsNone)
							audio.volume = volume.Value;
						
						return;
					}
					else
					{
						if (!volume.IsNone)
							audio.PlayOneShot(oneShotClip, volume.Value);
						else
							audio.PlayOneShot(oneShotClip);
						
						return;
					}
				}
			}
			
			// Finish if failed to play sound
			
			Finish();
		}
開發者ID:AlexanderUrbano,項目名稱:shapewars,代碼行數:35,代碼來源:AudioPlay.cs

示例4: ToggleDoors

	IEnumerator ToggleDoors () {
		m_Audio = audio;
		Debug.Log ("Toggling doors");
		if ((moving == false) & (down)) {
			moving = true;
			// play the start sound, if any
			if (SoundCloseDoors != null)
				m_Audio.PlayOneShot(SoundCloseDoors);
			GameObject.Find ("DoorElevator1_down").animation.Play ("close");
			GameObject.Find ("DoorElevator1_inside_down").animation.Play ("close");
			yield return new WaitForSeconds(2);
			Platform.SendMessage("GoTo", Platform.TargetedWaypoint == 0 ? 1 : 0, SendMessageOptions.DontRequireReceiver);
			yield return new WaitForSeconds(3);
			IsUp ();
		} else if ((moving == false) & (down == false)) {
			moving = true;
			if (SoundCloseDoors != null)
				m_Audio.PlayOneShot(SoundCloseDoors);
			GameObject.Find("DoorElevator1_up").animation.Play("close");
			GameObject.Find("DoorElevator1_inside_up").animation.Play("close");
			yield return new WaitForSeconds(2);
			Platform.SendMessage("GoTo", Platform.TargetedWaypoint == 0 ? 1 : 0, SendMessageOptions.DontRequireReceiver);
			yield return new WaitForSeconds(3);
			IsDown ();
		}
	}
開發者ID:PlayHopeless,項目名稱:game,代碼行數:26,代碼來源:Elevator1_Toggle_Doors.cs

示例5: ToggleDoors

	IEnumerator ToggleDoors () {
		m_Audio = audio;
		Debug.Log ("Toggling doors");
		if ((moving == false) & (down)) {
			Debug.Log ("Going UP");
			moving = true;
			// play the start sound, if any
			if (SoundCloseDoors != null)
					m_Audio.PlayOneShot (SoundCloseDoors);
			DoorFence.animation.Play ("close");
			OutsideDoorBot.transform.Find ("Door_Bot").animation.Play ("bot_close");
			OutsideDoorBot.transform.Find ("Door_Top").animation.Play ("top_close");
			yield return new WaitForSeconds (2);
			Platform.SendMessage ("GoTo", Platform.TargetedWaypoint == 0 ? 1 : 0, SendMessageOptions.DontRequireReceiver);
			yield return new WaitForSeconds (54); // 17 para 0.01 de velocidad. 54 para 0.002
			IsUp ();
		} else if ((moving == false) & (down == false)) {
			Debug.Log ("Going DOWN");
			moving = true;
			if (SoundCloseDoors != null)
					m_Audio.PlayOneShot (SoundCloseDoors);
			DoorFence.animation.Play ("close");
			OutsideDoorTop.transform.Find ("Door_Top").animation.Play ("top_close");
			OutsideDoorTop.transform.Find ("Door_Bot").animation.Play ("bot_close");
			yield return new WaitForSeconds (2);
			Platform.SendMessage ("GoTo", Platform.TargetedWaypoint == 0 ? 1 : 0, SendMessageOptions.DontRequireReceiver);
			yield return new WaitForSeconds (54); // 17 para 0.01 de velocidad. 54 para 0.002
			IsDown ();
		} else {
			Debug.Log ("Error");
		}
	}
開發者ID:PlayHopeless,項目名稱:game,代碼行數:32,代碼來源:SuperElevatorSystem.cs

示例6: ToggleDoor

	IEnumerator ToggleDoor () {
		m_Audio = audio;
		Debug.Log ("Toggling door");
		if ((moving == false) & (door_open)) {
			Debug.Log ("closing");
			moving = true;
			// play the start sound, if any
			if (SoundCloseDoors != null)
				m_Audio.PlayOneShot(SoundCloseDoors);
			door.transform.Find ("Door_Top").animation.Play ("top_close");
			door.transform.Find ("Door_Bot").animation.Play ("bot_close");
			yield return new WaitForSeconds(2);
			IsClose();
		} else if ((moving == false) & (door_open == false)) {
			Debug.Log ("opening");
			moving = true;
			// play the start sound, if any
			if (SoundCloseDoors != null)
				m_Audio.PlayOneShot(SoundCloseDoors);
			door.transform.Find ("Door_Top").animation.Play ("top_open");
			door.transform.Find ("Door_Bot").animation.Play ("bot_open");
			yield return new WaitForSeconds(2);
			IsOpen();
		}
	}
開發者ID:PlayHopeless,項目名稱:game,代碼行數:25,代碼來源:DoorSecureAccessManager.cs

示例7: PlayGetTakenOverSound

	public IEnumerator PlayGetTakenOverSound(AudioSource source)
	{
		float delay = 0.08f;
		source.PlayOneShot(GetNote(8));
		yield return new WaitForSeconds(delay);
		source.PlayOneShot(GetNote(7));
		yield return new WaitForSeconds(delay);
		source.PlayOneShot(GetNote(6));
	}
開發者ID:jquentin,項目名稱:LaserPin,代碼行數:9,代碼來源:GameController.cs

示例8: playSound

	public AudioSource playSound(SoundClips clip, AudioSource source) {

		if (source == null) {
			source = gameObject.AddComponent<AudioSource>();
			source.PlayOneShot(mAudioClips [(int)clip]);
			Destroy(source,mAudioClips [(int)clip].length + 1);
		} else {
			source.PlayOneShot (mAudioClips [(int)clip]);
		}

		return source;
	}
開發者ID:cnrshantanu,項目名稱:Turkesh,代碼行數:12,代碼來源:SoundManager.cs

示例9: Start

    // Use this for initialization
    void Start()
    {
        player = GameObject.Find ("Player");

        objCnt = 0;
        dieTimer = 0.0f;
        duration = 0.0f;

        audio = GetComponent<AudioSource>();
        audio.PlayOneShot (aDown, 0.4f);
        audio.PlayOneShot (aAttack, 0.4f);
    }
開發者ID:gunsct,項目名稱:final_project,代碼行數:13,代碼來源:Lightning.cs

示例10: Start

	// Use this for initialization
	void Start () {
		flag = 0;
		temp = renderer as SpriteRenderer;
		m_sound = this.audio;
		m_sound.PlayOneShot (sound);

	}
開發者ID:yenchenLiu,項目名稱:Crush-Of-Clans,代碼行數:8,代碼來源:BombAnimation.cs

示例11: Start

		void Start()
		{
			startTime = Time.time;
			pEmitters = gameObject.GetComponentsInChildren<KSPParticleEmitter>();
			foreach(KSPParticleEmitter pe in pEmitters)
			{
				pe.emit = true;	
				pe.force = (4.49f * FlightGlobals.getGeeForceAtPosition(transform.position));
				if(pe.maxEnergy > maxTime)
				{
					maxTime = pe.maxEnergy;	
				}
			}
			lightFX = gameObject.AddComponent<Light>();
			lightFX.color = Misc.ParseColor255("255,238,184,255");
			lightFX.intensity = 8;
			lightFX.range = 50;
			
			exSound = GameDatabase.Instance.GetAudioClip("BDArmory/Sounds/explode1");
			audioSource = gameObject.AddComponent<AudioSource>();
			audioSource.minDistance = 20;
			audioSource.maxDistance = 1000;
			audioSource.volume = Mathf.Sqrt(GameSettings.SHIP_VOLUME);
			audioSource.PlayOneShot(exSound);
		}
開發者ID:kevincoggins,項目名稱:BDArmory,代碼行數:25,代碼來源:ExplosionFX.cs

示例12: Start

	// Use this for initialization
	void Start () {

		supportive = GetComponent<AudioSource>();

		// This is some instantiation.
		// We want it so that if the player is within a + direction from the particle, they will get hurt.
		GameObject player = GameObject.FindGameObjectWithTag("Player");
		int playerX = (int)player.transform.position.x;
		int playerY = (int)player.transform.position.y;

		Coord myPlace = new Coord((int)this.transform.position.x, (int)this.transform.position.y);
		Coord playerCoord = new Coord(playerX, playerY);
		Coord n, w, s, e;
		n = playerCoord.nextCoord (Direction.North);
		w = playerCoord.nextCoord (Direction.West);
		s = playerCoord.nextCoord (Direction.South);
		e = playerCoord.nextCoord (Direction.East);

		if( myPlace.isEqual (playerCoord) ||
		    myPlace.isEqual (n) ||
		    myPlace.isEqual (w) ||
		    myPlace.isEqual (s) ||
		    myPlace.isEqual (e) ) {
			PlayerMovement hitPlayer = player.GetComponent<PlayerMovement>();
			supportive.PlayOneShot(haha,1f);
			hitPlayer.LoseHealth(750); }

		Destroy (this.gameObject, 3);

	}
開發者ID:starrodkirby86,項目名稱:Better-Game-App,代碼行數:31,代碼來源:EvilDamage.cs

示例13: Start

    // Use this for initialization
    void Start () {

        gm = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameManagerScript>();
        source = GetComponentInChildren<AudioSource>();
        rb = GetComponent<Rigidbody2D>();
        rend = GetComponentInChildren<Renderer>();
        circleCollider = GetComponent<CircleCollider2D>();
        letter = GetComponentInChildren<TextMesh>();

        char[] alphabet = "AABCDEEEFGHIIJKLMNOOPQRSTUVWXYZ".ToCharArray();
        int randomLetter = Random.Range(0, alphabet.Length);
        letter.text = alphabet[randomLetter].ToString();

        if ("AEIOU".Contains(letter.text))
        {
            letter.color = vowelColor;
        }
        
        timeToLive = Time.time + timeToLive;

        rb.drag = 0;

        float x = Random.Range(-1.0f, 1.0f);
        float y = Random.Range(-1.0f, 1.0f);
        int speed = Random.Range(50, 150);

        source.PlayOneShot(bubbleSpawn, .5f);
        rb.AddForce(new Vector2(x, y) * speed);
    }
開發者ID:slayer3600,項目名稱:BubbleWordGame,代碼行數:30,代碼來源:BubbleScript.cs

示例14: PlaySoundOneShot

 public static void PlaySoundOneShot(AudioClip audioClip, AudioSource audioSource)
 {
     if (gameSounds == GameSounds.enabled)
     {
         audioSource.PlayOneShot(audioClip);
     }
 }
開發者ID:NemOry,項目名稱:EscapeTheNemories,代碼行數:7,代碼來源:GameSettings.cs

示例15: Start

    // Use this for initialization
    void Start () {

        Cat = GameObject.FindObjectOfType<PlayerController>();
        audioSource = gameObject.GetComponent<AudioSource>();
        SinusAmpRatio = Random.RandomRange(0, 0.25f);
        SinusFreqRatio = Random.RandomRange(0, 2f);

        transform.localScale = new Vector3(transform.localScale.x * Random.value > 0.5f ? 1 : -1, transform.localScale.y, transform.localScale.z);

        float distance = transform.position.z - Camera.main.transform.position.z;
        Vector3 leftMostCamera = Camera.main.ViewportToWorldPoint(new Vector3(0.0f, 0, distance));
        Vector3 rightMostCamera = Camera.main.ViewportToWorldPoint(new Vector3(1f, 0, distance));
        Vector3 topMostCamera = Camera.main.ViewportToWorldPoint(new Vector3(0, 0, distance));
        Vector3 botMostCamera = Camera.main.ViewportToWorldPoint(new Vector3(1, 1, distance));
        print(rightMostCamera.x);
        x_min = leftMostCamera.x + X_sprite_padding;
        x_max = rightMostCamera.x - X_sprite_padding;
        y_min = topMostCamera.y + Y_sprite_padding;
        y_max = botMostCamera.y - Y_sprite_padding;

     
    
        float x_speed = Random.Range(0, Speed);
        float y_speed = Speed - x_speed;
        speed_vector = new Vector3(x_speed, y_speed,0);


        audioSource.PlayOneShot(SpawnSound);
        InvokeRepeating("SpontaniusDirectionChange", 3f, 3f);

    }
開發者ID:Sarnir,項目名稱:TheCatromancer,代碼行數:32,代碼來源:BatterfuckerBehaviour.cs


注:本文中的UnityEngine.AudioSource.PlayOneShot方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。