Unity - Play Sound Effect During Collision (OnCollisionEnter2D) | EASY Unity Tutorial

Поделиться
HTML-код
  • Опубликовано: 1 окт 2024

Комментарии • 29

  • @SkopidOHNS
    @SkopidOHNS Год назад +3

    Thanks buddy, I've been searching for so long, for a good tutorial simple and working

  • @TakaShitake-rt8bz
    @TakaShitake-rt8bz Год назад +1

    but I want this for like bullets hitting and exploding on a surface and an impacteffect particle system gets instantiated and then like all the gameObjects like my "bullet" and my "explosion" disappear - so I am guessing that instead of my audiosource being a gameObject I should make it a prefab? But wait a minute your tutorial is really good - as I was looking at this initially the wrong way - like I was focusing too much on tying my "explosion" to the bullet or impactEffect which gets destroyed - and Unity of course bitches about unable to play a null sound and all that B.S. - so aha, keep the audioSource as like it's own separate public gameObject and have the script refer to it - but even when the bullet and the impactEffect get destroyed, my audio gameObject "remains" in the game and no more audio errors? thanks a million. I'll try it.

  • @Tony-un9mg
    @Tony-un9mg 2 года назад +2

    Thank you so mush! Creating a new gameobject solved my problem.

    • @TakaShitake-rt8bz
      @TakaShitake-rt8bz Год назад

      I think this is the true genius of this tutorial - as my problem with bullets and explosions was me keep trying to tie explosion sounds to either bullets or explosion impactEffects that get destroyed in the world and Unity bitches about cannot play a null audio etc so yeah wow smart solution I need to now try this. Subscribed

  • @nikocounters2
    @nikocounters2 7 месяцев назад

    Thanks buddy but jumpscare is something different from scaresound!

  • @NoobNoob11037
    @NoobNoob11037 Год назад +1

    does the audio file have to be a specific type? i did everything you said but wont let me put the audio file into the audio player

    • @Dobbo151
      @Dobbo151 8 месяцев назад

      Yeah, the audio file formats that Unity can import are .aif, .wav, .mp3, and .ogg

  • @xDTHECHEMISTx
    @xDTHECHEMISTx Год назад

    Do you have any code methods where when the player collides with an enemy it knocks the player backwards a bit with a stun? Kinda like old mega man and castlevania games for example

  • @popkeyrt10
    @popkeyrt10 Год назад

    i need help the discord isnt working

  • @voiceofomiej7722
    @voiceofomiej7722 7 месяцев назад

    Great

  • @emirhankızıl-z9w
    @emirhankızıl-z9w 6 месяцев назад

    Thank you

  • @giannoulalalabazinga5721
    @giannoulalalabazinga5721 Год назад

    God thanks!

  • @remymanee
    @remymanee Год назад

    perfect vid thanks bro

  • @nine9winged
    @nine9winged Год назад

    Thanks bro!

  • @aleksboboychev
    @aleksboboychev Год назад

    Cheers Boss!

  • @jawbytes380
    @jawbytes380 Год назад

    How do I get my enemy to play a sound when my player gets close to the enemy?

    • @TakaShitake-rt8bz
      @TakaShitake-rt8bz Год назад

      do a raycast and use raycast.length whatever it is to set the "distance"

  • @peteypeetepete
    @peteypeetepete 2 года назад +4

    and if you are coding in 3d?

    • @ultimav3868
      @ultimav3868 Год назад +1

      Then you change OnCollisionEnter3D

    • @manunavoni7666
      @manunavoni7666 Год назад +1

      @@ultimav3868 Shouldn't he change it to OnCollisionEnter ( Collision , collision)?

  • @pustota7254
    @pustota7254 2 года назад

    Works

  • @alexander_kozin9214
    @alexander_kozin9214 2 года назад

    Thanks a ton, it helped

  • @dj_tika
    @dj_tika 2 года назад +1

    I'm going bonkers, I tried several things in my 2D Panchinko project to get a sound to play when the ball collides with one of the pegs, nothing is working, I have tried with and without tags, moving code around in C#, moving the order of components, literally nothing is working, the sound simply won't play and I don't know why :/

    • @jazhinx
      @jazhinx 2 года назад

      did u solve this problem?

    • @dj_tika
      @dj_tika 2 года назад

      @@jazhinx yes I did actually, I used a script I found that some lady made here on RUclips of a ball falling on a trampoline in 2D, it was way simpler than I thought it would be lol

    • @jazhinx
      @jazhinx 2 года назад

      @@dj_tika i see, lookin' for that then HAHA tysm

    • @Tryftz
      @Tryftz 2 года назад

      @@dj_tika how’s the game going mow

  • @TakaShitake-rt8bz
    @TakaShitake-rt8bz Год назад

    yeah - just like bullets and impactEffects that disappear from the world are handled via prefabs, I'm now inclined to conclude - that my audioSource instead of a gameObject sitting in the hierarchy - needs to be also a prefab - and I need to code an instantiation of the audioSource prefab that gets played when the bullet collides with a target I want it to "ricochet" off etc. hmm. ok you really set me on the right path with this thanks - this is a b*tch for when you want to apply to objects that get destroyed like projectiles and explosions - they are there one update loop but then gone on the next iteration of update lol