Unity 3D- on trigger enter or exit play stop sound

Informations relatives au logiciel de 3D temps réel Unity
yann.minh
Site Admin
Messages : 1160
Inscription : dim. févr. 11, 2007 7:44 pm

Unity 3D- on trigger enter or exit play stop sound

Message par yann.minh »

On trigger enter, play or stop sound

Code : Tout sélectionner

function OnTriggerEnter(otherObj: Collider){
    if (otherObj.tag == "Player"){
        audio.Play();
    }
}

function OnTriggerExit(otherObj: Collider){
    if (otherObj.tag == "Player"){ 
        audio.Stop();
    }
}
Répondre