How to Play Audio from a Script in Unity

Поділитися
Вставка
  • Опубліковано 26 лис 2024

КОМЕНТАРІ • 44

  • @MattRaffel
    @MattRaffel 4 роки тому +21

    This video is missing probably the most important piece. Creation and initialization of the AudioSource component.

    • @AdamFBuchanan
      @AdamFBuchanan 3 роки тому +1

      gamedevbeginner.com/how-to-play-audio-in-unity-with-examples/ this is the article he put in the description which explains implementation.

  • @GoobNoob
    @GoobNoob 2 роки тому +1

    Very good and clear video on all the AudioSource Playing Topics

  • @Kantrul
    @Kantrul Рік тому

    Quick, concise and useful. Very good explanation!

  • @AdamFBuchanan
    @AdamFBuchanan 3 роки тому +3

    I found your article on this a week ago. Loved it. Thanks for making a video also in this age of watching rather than reading :/ haha

    • @aaronschneider1581
      @aaronschneider1581 3 роки тому

      Same, specifically came to the video to give a thumbsup^^
      Helpful article for a Unity-noob

    • @GameDevBeginner
      @GameDevBeginner  3 роки тому

      Thank you both, I appreciate it.

  • @Mikelica69
    @Mikelica69 3 роки тому

    Hey i just readed your 10 Unity Audio Tips article, good work :)

  • @CleisonRodriguesComposer
    @CleisonRodriguesComposer 4 роки тому +1

    The best tutorial about audio!
    Thank you!

  • @Arctic.Wolves
    @Arctic.Wolves 4 роки тому +1

    Thanks for your method, cheers

  • @kerimozdemir4009
    @kerimozdemir4009 4 роки тому +1

    Good and to the point thanks

  • @hammyrocks478
    @hammyrocks478 4 роки тому +1

    Great quality video!

  • @hammyrocks478
    @hammyrocks478 4 роки тому +1

    This was greatly needed!

  • @klaus117gaming
    @klaus117gaming 2 роки тому +1

    You have no idea how long I’ve been looking for this explanation… I’m working on a game and noticed my audio gets cut off if I rapid fire and had no clue what was wrong. Thank you

  • @deadlybug
    @deadlybug 4 роки тому +1

    I love this scenery. It's beautiful. Do you have a full video showing it?

    • @GameDevBeginner
      @GameDevBeginner  3 роки тому +1

      You can see more of the scenery in my sound design videos here: johnleonardfrench.com/articles/unity-audio-tutorial-series-adding-sounds-to-the-sun-temple/ or you can download the asset. It's the Sun Temple but Sandro T and it's free

  • @SoyelAlejandro33
    @SoyelAlejandro33 3 роки тому

    hi mate! great video. What would you do for auto fire gunshots sounds to play evenly? Thanks

  • @nerfman29
    @nerfman29 3 роки тому

    This is extremely useful! Thank you for this video!

  • @frustis
    @frustis 3 роки тому +2

    Amazing video! Thanks so much. And sorry for asking about this on an audio related video, but how did you create those clouds, and how did you place that grass?

    • @GameDevBeginner
      @GameDevBeginner  3 роки тому

      Everything you see here is the Sun Temple asset by Sandro T on the Asset Store, it's also free.

    • @sonnenklang6925
      @sonnenklang6925 11 місяців тому

      ​@@GameDevBeginnerhi, does free also include making a public vrchat world with it, adding my own elements or use parts of it, like 4xample only the Central Building? THX :)

  • @cowragerzzz678
    @cowragerzzz678 4 роки тому +2

    Great video, was very informative! I'm just wondering how to loop my audio via a script as you didn't exactly touch base on that. Is there a .loop method I'm missing or is it part of the .play() syntax? Thanks!

    • @GameDevBeginner
      @GameDevBeginner  4 роки тому +3

      It's an Audio Source property. You can either set it in the Inspector or you can access it via script (e.g. audioSource.loop = true;)

  • @alwayssoftgames6636
    @alwayssoftgames6636 2 роки тому

    Is it possible to delay an audio clip? So delay the the start of PlayOneShot, so that the audioclips don't start for half a second or so

    • @GameDevBeginner
      @GameDevBeginner  2 роки тому

      It is possible, with Play Delayed or Play Scheduled, but not with Play One Shot as far as I know. But you could put Play One Shot in a function and then delay that using Invoke, or a coroutine.

    • @alwayssoftgames6636
      @alwayssoftgames6636 2 роки тому

      @@GameDevBeginner Yeah that's what I was thinking of trying aswell, thanks

  • @nowherecrafter
    @nowherecrafter 8 місяців тому

    What is the game on the footage? Is it available anywhere?

    • @GameDevBeginner
      @GameDevBeginner  8 місяців тому

      It's a Unity asset, the Sun Temple, available here: assetstore.unity.com/packages/3d/environments/sun-temple-115417

  • @walney2008
    @walney2008 3 роки тому

    hello, piano project, each key on the keyboard plays a note, through the sound clip, how to play it alone? that is, according to the line of the music, I must perform 1 to 7 notes in the sequence, how to do this?
    Congratulations to You (Musical Notes)
    Grades:
    DO-DO-RE-DO-FA-MI
    DO-DO-RE-DO-DO-SOL-FA
    LA-LA-DO-LA-FA-MI-RE
    LA-LA-SOL-FA-SOL-FA

  • @blt2654
    @blt2654 3 роки тому

    wait how do i define audioSource

  • @Andrew90046zero
    @Andrew90046zero 4 роки тому

    In my game I have an item that makes 2 separate sounds when used. One that is played immediately, and another that is played after a delay and if the item was used successfully. So sometimes only the first sound will play. I want to have the first sound stop playing if the item was used successfully, but only after the delay. So you would hear the first sound, and after 0.1 seconds it would cut out and play the second sound.
    I tried using 1 audio source and then using the playDelayed function to play the second sound, but for some reason it seems to cut out the first sound completely, and you only hear the second sound. I think it’s because of the audio clip being changed?
    I tried making a special mono behavior that would basically control the audio source and carry out the delay I wanted before setting the new audio clip, and that seems to work. I just wanted to ask if this seems like a normal solution or if anyone has came up with any different solutions. Thanks in advance.

    • @GameDevBeginner
      @GameDevBeginner  3 роки тому

      Play Delayed, just like PlayScheduled works like Play, in that it cuts out other sounds and will appear to be playing (by checking isPlaying) even before the clip starts. One way you could do this instead is with a Coroutine and Wait for Seconds and just use the normal Play function if and when you need it.

  • @BorisAverin
    @BorisAverin 2 роки тому

    Огромное спасибо!!!

  • @EthanEDITS1
    @EthanEDITS1 3 роки тому

    Great video! I just cant decide whether to subscribe or not because you are at 69 subs...

  • @gomango99
    @gomango99 3 роки тому

    Not on topic but... how is so much stuff on your taskbar???? 😂

  • @GrumpyIdiot
    @GrumpyIdiot 2 роки тому

    ok amazing video
    im making a game where there is a day and night cycle and i want the birds audio clip to play at a specific time in the morning but i dont know how, i have been wondering around for three days and nothing works, im so new so im really dumb so should i use play scheduled?

    • @GameDevBeginner
      @GameDevBeginner  2 роки тому +1

      Off the top of my head, maybe try storing a global time of day value and use events to connect up things that need to happen throughout the day. To avoid having every event check constantly if something is due, keep one list of all the events and check their due time against the time of day every 5 mins. (see my events video for an idea of how to do this: ua-cam.com/video/J01z1F-du-E/v-deo.html or Ryan Hipple's 2017 Austin talk, particularly the bit on runtime sets: ua-cam.com/video/raQ3iHhE_Kk/v-deo.html).
      It's a rough idea, but that's how I d approach it.

    • @GrumpyIdiot
      @GrumpyIdiot 2 роки тому

      @@GameDevBeginner thank you so much!! I'll try that and hopefully it will work!!
      But I have an event that makes the street lights turn off and on, but I don't know how to use that to make the sound play, cuz whatever I type shows an error or it doesn't exist 😅 but yeah I don't know much so hopefully your videos will help!!