- Home /
Question by
gecko1 · May 11, 2015 at 12:09 PM ·
javascriptfunctionontriggerenteraudioclipplayoneshot
PlayOneShot in OnTriggerEnter function (Unity 5)
I'm making a simple survival zombie game and I've a little problem.
In the new Unity 5, PlayOneShot plays an AudioClip but, in a OnTriggerEnter function, that AudioClip plays when an object collides with a trigger, and it stop when that object leave the trigger.
But! In Unity 4.X the AudioClip was played and the sound continued although the object leaved the trigger.
What I can do?
This is my script (attached in Player):
var scream : AudioClip;
function OnTriggerEnter (player : collider) {
if (player.gameObject.tag == "Zombie") {
GetComponent.<AudioSource>().PlayOneShot(scream);
}
}
Thank you all!
Comment