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

Поделиться
HTML-код

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

  • @FookerCarlson
    @FookerCarlson 27 дней назад

    Thanks so much! Didn't know I could use this on games, used it on a coding assignment last year, lol!

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

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

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

    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

  • @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.

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

    Thanks bro!

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

    Thanks buddy but jumpscare is something different from scaresound!

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

    Thank you

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

    perfect vid thanks bro

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

    Cheers Boss!

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

    Thanks a ton, it helped

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

    God thanks!

  • @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

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

    Great

  • @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 10 месяцев назад

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

  • @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

  • @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

  • @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"

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

    Works

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

    i need help the discord isnt working

  • @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)?