Unity 3D Play Audio Sound OnTriggerEnter

Advertisemen




Unity 3D Play Audio Sound OnTriggerEnter





Making free platform game ! One man show

----------------------------------------­----------------------------------------­---
Javascrip: GOOD 4 2D GAMES AND 3D GAMES !
----------------------------------------­----------------------------------------­---


var soundFile:AudioClip;


function OnTriggerEnter(trigger:Collider) { if(trigger.collider.tag=="Player&qu­ot;) { audio.clip = soundFile; audio.Play(); }

}


---------------------------------------------------------------

Dear members  here is alternatives !


All Java Scripts  name it how you like !


------------------------------------------------------------------------------------

First Java script is for looping music after trigger enter :
------------------------------------------------------------------------------------
var Sound :AudioClip;
function OnTriggerEnter() {
audio.clip = Sound;
audio.Play();
}
function OnTriggerExit(){
audio.Stop();
}



-----------------------------------------------------------------------------------
Second Java script is for sounds to fire only once:
-----------------------------------------------------------------------------------
private var hasPlayed : boolean = false;
var Sound : AudioClip;
function OnTriggerEnter() {
if(!hasPlayed){
audio.clip = Sound;
audio.Play();
hasPlayed = true;
}
}




------------------------------------------------------------------------------------------------------------
Third Java script is for trigger sounds (fire every time you enter a trigger):
------------------------------------------------------------------------------------------------------------

var Sound : AudioClip;
function OnTriggerEnter() {
audio.clip = Sound;
audio.Play();
}



made with ezvid, free download at http://ezvid.com

Advertisemen

Disclaimer: Gambar, artikel ataupun video yang ada di web ini terkadang berasal dari berbagai sumber media lain. Hak Cipta sepenuhnya dipegang oleh sumber tersebut. Jika ada masalah terkait hal ini, Anda dapat menghubungi kami disini.

Tidak ada komentar:

Posting Komentar

© Copyright 2017 Tutorial Unity 3D