本文整理汇总了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]);
}
}
示例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;
}
}
示例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();
}
示例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 ();
}
}
示例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");
}
}
示例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();
}
}
示例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));
}
示例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;
}
示例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);
}
示例10: Start
// Use this for initialization
void Start () {
flag = 0;
temp = renderer as SpriteRenderer;
m_sound = this.audio;
m_sound.PlayOneShot (sound);
}
示例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);
}
示例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);
}
示例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);
}
示例14: PlaySoundOneShot
public static void PlaySoundOneShot(AudioClip audioClip, AudioSource audioSource)
{
if (gameSounds == GameSounds.enabled)
{
audioSource.PlayOneShot(audioClip);
}
}
示例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);
}