当前位置: 首页>>代码示例>>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;未经允许,请勿转载。