Play and wait for audio to finish playing

前端 未结 2 1133
广开言路
广开言路 2021-01-22 07:52

in my project I want a sound to play and then for an objects active state to be set to false, at the moment both are happening at the same time so the sound doesn\'t play. If I

2条回答
  •  遥遥无期
    2021-01-22 08:28

    You could hide the object using its renderer, as well as turning off any colliders, play the sound, then destroy/set it to inactive:

    renderer.enabled = false;
    gameObject.collider.enabled = false;
    
    audio.PlayOneShot(someAudioClip);
    Destroy(gameObject, someAudioClip.length); //wait until the audio has finished playing before destroying the gameobject
    // Or set it to inactive
    

提交回复
热议问题