1

Как сделать, чтобы выполнялось какое-то действие при завершении клипа в AudioSource.

1 ответ 1

3

Например так:

public AudioClip someClip;

 
void Start() {
    StartCoroutine(playSound());
}
 
IEnumerator playSound() {    
    GetComponent<AudioSource>().clip = someClip;
    GetComponent<AudioSource>().Play();
    yield return new WaitForSeconds(someClip.length);
    
    doAdditionalCationAfterClipFinish();    
}

void doAdditionalCationAfterClipFinish() {
    // что-то сделать
}
3
  • 2 ошибки: 'AudioSource' does not contain a definition for 'length' and no accessible extension method 'length' accepting a first argument of type 'AudioSource' could be found (are you missing a using directive or an assembly reference?) и Cannot implicitly convert type 'UnityEngine.AudioSource' to 'UnityEngine.AudioClip' 25 мая 2021 в 11:09
  • @KlimeLime да. в самом начале надо было public AudioClip someClip; а не public AudioSource someClip; Поправил 26 мая 2021 в 6:35
  • Всё работает отлично! 27 мая 2021 в 6:43

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.