Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Can not play a disabled audio source UnityEngine.AudioSource:PlayOneShot(AudioClip). Pls Help Thx!

Discussion in 'Scripting' started by Yair123456789, Nov 28, 2023.

  1. Yair123456789

    Yair123456789

    Joined:
    Dec 21, 2021
    Posts:
    12
    Code (CSharp):
    1. IEnumerator PlayAudio()
    2.     {
    3.         if (question.questionType == QuestionType.AUDIO)
    4.         {
    5.             questionAudio.PlayOneShot(question.qustionClip);
    6.  
    7.             yield return new WaitForSeconds(audioLenght + 0.5f);
    8.  
    9.             StartCoroutine(PlayAudio());
    10.         }
    11.         else
    12.         {
    13.             StopCoroutine(PlayAudio());
    14.             yield return null;
    15.         }
    16.     }
     

    Attached Files:

    Last edited: Nov 29, 2023
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,761
  3. Yair123456789

    Yair123456789

    Joined:
    Dec 21, 2021
    Posts:
    12