本文整理汇总了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 ();
//}
}
}
示例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);
}
}
}
示例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]);
}
}
示例4: Start
// Use this for initialization
void Start()
{
aSource = GetComponent<AudioSource>();
aSource.Play();
aSource.clip = song1;
aSource.Play();
}
示例5: PlayAudioSource
public void PlayAudioSource(AudioSource audioSource)
{
if (AudioSources.Contains(audioSource)) {
if (AllowClipping)
audioSource.Play();
else if (AudiosBeingPlayed() == 0)
audioSource.Play();
}
}
示例6: playSound
void playSound(AudioSource sound)
{
if (sound.isPlaying)
{
sound.Stop();
sound.Play();
}
else
sound.Play();
}
示例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>();
}
示例8: Start
void Start()
{
audioSrc = GetComponentInChildren<AudioSource> ();
audioSrc.clip = BGM_main;
audioSrc.Play (0);
//audioSrc.ignoreListenerVolume = true;
}
示例9: Start
// Use this for initialization
void Start()
{
sE = gameObject.AddComponent<AudioSource>();
sE.clip = pop [Random.Range(0, 4)];
sE.volume = seVolume;
sE.Play ();
}
示例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();
}
示例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();
}
}
示例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);
}
示例13: Awake
void Awake()
{
audioSource = GetComponent<AudioSource>();
audioSource.clip = MenuSoundEffect;
audioSource.Play();
EventManager.StartListening( EventDictionary.ON_ENTER_GAME_STATE, OnEnterGame );
}
示例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());
}
}
示例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
}
}