Monday 19 January 2015

Unity 3D Play Audio Sound OnTriggerEnter




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

9 comments:

  1. TriggerEnter 2 is also my favorite sound player. thanks for the post.
    https://www.youtube.com/watch?v=vgWmA2Qn8zc

    ReplyDelete
  2. Thanks for sharing that information with us really informative.. Keep posting and I'm waiting for your
    upcoming response..Thanks
    code xbox live gold

    ReplyDelete
  3. I'm trying to find some good music to relax and meditat too. I don't usually listen to it so i'm not framiliar with it but i need some songs that are like sound effects kind of like, Rain, the ocean, the rainforrestt, etc. I also enjoy that like indian? Buddha? music. Like Shakra or something like that. Or just like piano music, something that will bring me to another place when i close my eyes, like the middle of a field full of flowers. Thank you.
    Kevin Mongelli Music

    ReplyDelete
  4. NIce article this article has been my favorite, interesting and informative article.
    Mobile

    ReplyDelete
  5. Amazing and interesting photos. really love games and all information.
    overwatch

    ReplyDelete
  6. Interesting blog about the games and i really love and like your blog keep it up.
    catan board game

    ReplyDelete
  7. Great article, this is such an interesting and informative article.
    The Walking Dead

    ReplyDelete
  8. What are some good websites to play free online games?
    free online games to play

    ReplyDelete
  9. Hey we just launched a Gaming Platform games online free where you can play over thousand games for free, earn POINTS to get on the leaderboard and also add games as a developer or player to the platform.

    ReplyDelete