Search Unity

Question Need help with AudioClip and AudioSource

Discussion in 'Audio & Video' started by Daniel_Rusu25, Jan 21, 2024.

  1. Daniel_Rusu25

    Daniel_Rusu25

    Joined:
    Jan 5, 2024
    Posts:
    16
    I got a CarController from online, in which it is used through all the code AudioSource as a variable to store the engine sound. I have imported some engine sounds which came as AudioClips and cannot add them to the script. Tried to change the declaration from AudioSource to AudioClip, but then it breaks the entire code.
    Is there a way to convert the AudioClip file into AudioSource?
     
  2. Hikiko66

    Hikiko66

    Joined:
    May 5, 2013
    Posts:
    1,304
    An audioclip is a sound. An Audiosource is something that plays audioclips.
    Audioclips can't play themselves, so an audiosource and an audioclip are different things.

    You assign the audioclip you want to play, to the audiosource that is going to play it.

    myAudioSource.clip = myAudioClip;
    myAudioSource.Play();
     
  3. Daniel_Rusu25

    Daniel_Rusu25

    Joined:
    Jan 5, 2024
    Posts:
    16
    Thank you so much!